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?
Asked
Active
Viewed 3.7k times
43

cahen
- 15,807
- 13
- 47
- 78
-
Where you on a branch when you ran that, or a detached head? – Jonathan Wakely Jun 05 '13 at 16:25
-
1possible duplicate of [Undoing git reset?](http://stackoverflow.com/questions/2510276/undoing-git-reset) – 0xc0de Dec 29 '13 at 21:14
3 Answers
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
-
this worked perfectly. If I used 2 instead of 1, it would go back 2 steps, right? – cahen Jun 06 '13 at 11:43
-
2Exactly. 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 Jun 06 '13 at 12:36
-
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.