5

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

user291701
  • 36,661
  • 70
  • 180
  • 281

3 Answers3

13

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.

Community
  • 1
  • 1
larsks
  • 228,688
  • 37
  • 348
  • 338
5

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.
Peter van der Does
  • 13,302
  • 4
  • 37
  • 42
2

Recovering from a borked/stupid/moribund rebase

Accidently I ran git pull origin master --rebase instead of git pull origin develop --rebase.

I just wanted to revert what happened after rebase and get back to the last commit. I did not push to the remote branch.

It was a big mistake and want to get out of the merge.

The fastest way out of the merge is git rebase --abort

irfanbaigse
  • 58
  • 2
  • 7