'How to undo 'git reset'?
What's the simplest way to undo:
git reset HEAD~
Currently, the only way I can think of is doing a git clone http://... from a remote repo.
Solution 1:[1]
Old question, and the posted answers work great. I'll chime in with another option though.
git reset ORIG_HEAD
ORIG_HEAD references the commit that HEAD previously referenced.
Solution 2:[2]
My situation was slightly different, I did git reset HEAD~ three times.
To undo it I had to do
git reset HEAD@{3}
so you should be able to do
git reset HEAD@{N}
But if you have done git reset using
git reset HEAD~3
you will need to do
git reset HEAD@{1}
{N} represents the number of operations in reflog, as Mark pointed out in the comments.
Solution 3:[3]
Use
git reflogto get all references update.git reset <id_of_commit_to_which_you_want_restore>
Solution 4:[4]
Answer works most time
git reset 'HEAD@{1}'
Answer works every time
git reset --hard 'HEAD@{1}'
where --hard makes everything keeps the same as before.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dan Fischer |
| Solution 2 | Rob Bednark |
| Solution 3 | Uwe Keim |
| Solution 4 | chener |
