Tensigh Tensigh - 8 days ago 5
Git Question

Git - how to reset a "push"

Somehow I have a really large local repository because I added over 2 GB of files by accident and without thinking tried to push this. I aborted, removed the files and did a recommit, but when I try to

git push origin master
to Bitbucket, it fails with:

fatal: The remote end hung up unexpectedly


My .git file is still huge, even though I have since long removed the unneeded files. Since the push is over 2 GB, Bitbucket says I need to set the
http.postBuffer
to a higher number. I've done this many times but after about 15 tries I want to just start over.

git status
gives me this:

On branch master
Your branch is ahead of 'origin/master' by 4 commits.
(use "git push" to publish your local commits)


But since the push never works, how do I fix it? Worst case scenario I could just blast the repo and rebuild it, but I'd like to know if there is a way to reset the push since it keeps failing.

Answer

The weigreen’s answer will help when the problematic commit is the most recent one, in other cases you’ll need to rewrite the history. I would prefer an interactive rebase.

git rebase -i <some-commit-before-the-problematic-one>

It will display the list of commits along with the default action to pick them as they are. If you want to keep a part of the problematic commit, change pick to edit on that line. If you prefer to remove it at all, just delete the line. If you choose to edit that commit, Git will put the working tree into the state like when you’ve just done the problematic commit. Change what you need and amend the commit:

git commit --amend

After that, let Git finish the rebase using

git rebase --continue