4

Quick preface, I have very little experience with git and other console based programs.

That being said, the problem at hand is that I used git reset --hard HEAD~ to roll back to a previous commit due to some corruption, but I ended up going one commit too far. Is there any way to undo the rollback or go forward a commit? I haven't synced it to the web yet.

Cœur
  • 37,241
  • 25
  • 195
  • 267
gamehen
  • 324
  • 1
  • 5
  • 18
  • 1
    Here are some other options for you as well:http://stackoverflow.com/questions/34519665/how-to-move-head-checkout-revet-reflog-reset/34519716#34519716 – CodeWizard Jan 17 '16 at 07:23

2 Answers2

5

git reflog | head should show you the commit ids you need to recover your lost commit.

xxxxxxx HEAD@{0}: reset: moving to HEAD~
yyyyyyy Your lost commit?

You can try the following

git checkout yyyyyy -b newbranch
git log newbranch

or

git cherry-pick yyyyyy
J.J. Hakala
  • 6,136
  • 6
  • 27
  • 61
4
git reset HEAD@{1}

This takes you back to before you reset wrong, assuming only ONE commit too far. From there you can reset again to the correct commit.

git reflog

Use this to see a list of updates. Each update is assigned with a HEAD number (for example, HEAD@{1}: reset: blah..blah..), you use this number to point to where you want to go just like the first command.

peanutz
  • 346
  • 3
  • 6
  • This worked well for me and seems simpler than the accepted answer. Generic: `git reset HEAD@{x}` - x being the number of commits you've gone too far. Though I haven't tried this with a hard reset, only after doing `git reset HEAD~y`. – gsvr Oct 10 '22 at 19:41