0

I've tried to revert last pushed commit to branch dev. After doing git push -f I realized that branch master was not at it's latest version on this machine, so I accidentally changed master as well.

My next step was to use different machine, where master was at latest version. The bad step was to run git pull on that machine, which updated all the branches, including master.

Is there any way to revert that last pull?

Dan
  • 55,715
  • 40
  • 116
  • 154
  • @HBHB I think I have different case, because the pull has force-updated commit tree, rather than fast-forwarded it – Dan Nov 09 '15 at 14:40
  • Have you looked at the `reflog`? In this case does that not `HEAD` you had before it was changed? – houtanb Nov 09 '15 at 14:42
  • 1
    I think that `git checkout master; git reset --hard HEAD@{1}` can solve your problem. – Nguyen Sy Thanh Son Nov 09 '15 at 14:42
  • 1
    The remedies in the linked-as-dup commit should work, though you have to do them on the machine that had the latest version of `master`. The "forced update" is only to (that machine's) `origin/master`, so as long as its *local* master is good, you should be able to recover. – torek Nov 09 '15 at 17:13

1 Answers1

0

There is no nice way of doing what you want, hence why a force push on git is highly advised against.

If you have the SHAs for the commits you've lost you can cherry-pick them, even though you can no longer see the commits in git any longer, it will still be able to reference them (I think!). Another option is to find another machine with the old commits on there, cherry-pick the commits you want, revert the commits you don't want and then do another git push -f. (And then try to never do a forced push again!)

mohammedkhan
  • 953
  • 6
  • 14