After reset --hard all my untracked files are gone

2019-07-22 14:26发布

问题:

I did a git hard reset without committing my files. After firing reset I checked all my untracked files are gone. I am expecting it will affect only the changes we made during the commit and it will simply reset those changes. But I was wrong.

Is there any way to get recover all my untracked files ? Any Help would be really really appreciated.

Thanks

回答1:

If you previously did a git add with your untracked files, then git reset --hard will delete them. Git has no process of restoring these because they are untracked. You will need to find another tool to do so, such as your operating system or IDE. IntelliJ has a "Local History" tool that you might be able to leverage for restoring these files.

For future reference, prefer git stash to git reset --hard. git stash creates a temporary "stash" commit with your changes. These can be easily retrieved with git stash apply or git stash pop. When you nuke your working directory with git reset --hard, it is much more difficult to undo, sometimes even impossible.