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? 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.

Sign up to request clarification or add additional context in comments.

3 Comments

this worked perfectly. If I used 2 instead of 1, it would go back 2 steps, right?
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.
always forget about reflog ><
12

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

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.