43

After running git reset HEAD~1, I noticed that actually there was nothing else to do and the commit was fine. Is there a way to revert this command?

2
  • Where you on a branch when you ran that, or a detached head? Commented Jun 5, 2013 at 16:25
  • 1
    possible duplicate of Undoing git reset?
    – 0xc0de
    Commented Dec 29, 2013 at 21:14

3 Answers 3

96

You can use:

git reset HEAD@{1}

This uses the last entry in the reflog. See git reflog if you did other things in between.

3
  • this worked perfectly. If I used 2 instead of 1, it would go back 2 steps, right?
    – cahen
    Commented Jun 6, 2013 at 11:43
  • 2
    Exactly. Have a look at git reflog to see which number corresponds to which commit. Have a look at man gitrevisions for those kinds of special syntax.
    – michas
    Commented Jun 6, 2013 at 12:36
  • always forget about reflog >< Commented Jun 29, 2016 at 5:50
12

You could see the commit id of that commit with git reflog.

3

Even easier (if you haven't done any other operations):

git reset ORIG_HEAD

ORIG_HEAD is the previous state of HEAD.

More details about HEAD vs. ORIG_HEAD are in the answer to this SO question.

Not the answer you're looking for? Browse other questions tagged or ask your own question.