Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo a git pull --rebase?

Tags:

git

I just ran

git pull --rebase

and forget to specify "origin". It looks like git pulled from all different branches. Is there a way to revert my repo from here to undo the pull?

Thanks

like image 962
user291701 Avatar asked Jun 06 '12 01:06

user291701


2 Answers

After a git pull operation, ORIG_HEAD should point to the previous value of HEAD. You should be able to:

git reset --hard ORIG_HEAD

And be back where you started before the pull operation. You can run:

git show ORIG_HEAD

To see exactly where ORIG_HEAD is pointing prior to running the reset command.

An alternative solution would be to create a new branch based on ORIG_HEAD:

git checkout -b newbranch ORIG_HEAD

Verify that things look the way you expect, then delete the old branch and rename new branch.

Also see this question for a discussion of HEAD and ORIG_HEAD and alternate syntaxes for referring to the same thing.

like image 118
larsks Avatar answered Oct 05 '22 22:10

larsks


Use git reflog

You will see a whole bunch of commits HEAD that are from the past.

Safest is to checkout the HEAD you need in a new branch and continue from there

git checkout -b phew HEAD@{x} # fill in the number of the commit you need.
like image 28
Peter van der Does Avatar answered Oct 05 '22 22:10

Peter van der Does