I was going to add some changes using git. Instead of committing my changes, I managed to write git reset --soft ~HEAD. How do I undo this command and get my changes back?
Asked
Active
Viewed 6,327 times
4
-
Have your working files been changed? – Tim Biegeleisen Mar 08 '16 at 08:27
-
After git reset --soft ~head, my changes dissapeared and the files from another commit appeared in my git status – TorK Mar 08 '16 at 08:29
-
I managed to fix this myself. Found this command and it worked: git reset HEAD@{1}. Thank you for your time :) – TorK Mar 08 '16 at 08:33
-
https://stackoverflow.com/a/2531803/470749 and https://stackoverflow.com/a/7844566/470749 helped me – Ryan Jan 31 '19 at 23:07
-
Does this answer your question? [How to revert an unnecessary "git reset HEAD~1"](https://stackoverflow.com/questions/16944826/how-to-revert-an-unnecessary-git-reset-head1) – Dherik Aug 07 '20 at 14:06
-
Are you sure you typed "~HEAD" and not "HEAD~"? If I type "git show ~HEAD --name-only" I get "fatal: ambiguous argument '~HEAD': unknown revision or path not in the working tree." – AJM Oct 22 '21 at 13:50
1 Answers
10
I managed to fix this myself. Found this command and it worked: git reset HEAD@{1}
TorK
- 477
- 2
- 10
- 26
-
1I was going to suggest this but I was afraid it wouldn't work. Luckily, you didn't do `git reset --hard ~HEAD`. This would have ended badly for you :-) – Tim Biegeleisen Mar 08 '16 at 08:34