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 Wakely– Jonathan Wakely2013-06-05 16:25:11 +00:00Commented Jun 5, 2013 at 16:25
- 1possible duplicate of Undoing git reset?0xc0de– 0xc0de2013-12-29 21:14:47 +00:00Commented 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.
3 Comments
cahen
this worked perfectly. If I used 2 instead of 1, it would go back 2 steps, right?
michas
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.theatlasroom
always forget about reflog ><
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.