I had some local changes in my directory that I committed using git commit. Later I realized that by mistake my changes broke my build. So I did a git reset --soft
on my repo.
But I screwed up, as I did not back up the changes that were all undone, as some of them did contain the new functionality that I wanted. Any help on how to undo a git reset --soft
operation so that I can get my committed changes back.
Asked
Active
Viewed 3.3k times
48
-
1The previous commit should still be in the reflog. But if you did a soft reset, shouldn't the changes still be in your working copy? – cHao Jan 10 '14 at 07:03
-
http://stackoverflow.com/questions/2510276/undoing-git-reset – Aaron Blenkush Jan 10 '14 at 07:03
-
Hi, thanks for the pointer. Actually what I just figured out is that I had forgot to do a "git add" for some of my local files. So when I actually did a commit in the first place, all the changes for those local files which were in "staged" phase, got committed and the unstaged changes got lost..Well now it seems that I am totally screwed. Is there a way out? – dennis Jan 10 '14 at 07:21
1 Answers
92
In $ git reflog
you should find some of your commits. Once you find the latest commit that you want to move to
you should reset back to your commit id $ git reset _Your_Hash_
, as $ git reset --soft
just reset the files and not the index or working tree.
-
4I still have a bunch of changes in `git status`. Before `git reset --soft` these were not there, so this answer as a general undo-this-git-command seems incomplete. – jozxyqk Mar 09 '17 at 23:58
-
4Thanks a ton, I panicked like hell, when I did git reset --soft HEAD~26 instead of 16 and force pushed. – gates Feb 10 '20 at 05:58