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?
-
Where you on a branch when you ran that, or a detached head?– Jonathan WakelyCommented Jun 5, 2013 at 16:25
-
1possible duplicate of Undoing git reset?– 0xc0deCommented Dec 29, 2013 at 21:14
Add a comment
|
3 Answers
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.
-
this worked perfectly. If I used 2 instead of 1, it would go back 2 steps, right?– cahenCommented Jun 6, 2013 at 11:43
-
2Exactly. Have a look at
git reflog
to see which number corresponds to which commit. Have a look atman gitrevisions
for those kinds of special syntax.– michasCommented Jun 6, 2013 at 12:36 -
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.