Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 411
Tensigh Avatar asked Nov 30 '16 07:11

Tensigh


People also ask

Can I revert a git push?

To revert, you can: Go to the Git history. Right click on the commit you want to revert. Select revert commit.

How do I delete a Git push?

Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .

How do I reset an old commit?

To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.


2 Answers

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
like image 95
Melebius Avatar answered Oct 08 '22 00:10

Melebius


You can do it by git reset

git reset --hard <commit-id>

You can get commit-id by using git log

You will lose all your work between HEAD and the commit you selected

like image 33
weigreen Avatar answered Oct 07 '22 23:10

weigreen