Im working on a Java project in intelliJ. I typed in the following command: "git reset --hard" in the terminal. How do I undo this command? Before this command I didnt commit anything. Is everything lost now?
There is 3 possibilities:
Your IDE has a feature to retrieve deleted file. Intellij (and all IDE by JetBrains) has this feature. Editors like VSCode, Atom, ... have extensions that could do that.
You already have staged your files (doing a git add
) before doing the reset, so git could help you retrieve some file contents (but not file names). See In Git, how can I recover a staged file that was reverted prior to committing? and https://edwardthomson.com/blog/introducing_git_recover.html (edit: I have since then created a git command line to help recover staged files. See https://stackoverflow.com/a/58853981/717372)
You didn't staged files, so all your files are lost from a git point of view :( You could still try to use a file recovery tool but it could become very difficult.
PS:
But don't forget one of the most important rule when using git "Commit everything and often (and especially before doing things you don't master). You will always be able to retrieve your changes/commits (at least using the reflog
)"