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?

cahen
  • 15,807
  • 13
  • 47
  • 78

3 Answers3

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.

michas
  • 25,361
  • 15
  • 76
  • 121
12

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

Adrian Panasiuk
  • 7,249
  • 5
  • 33
  • 54
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.

Community
  • 1
  • 1
Andrejs
  • 10,803
  • 4
  • 43
  • 48