



The file can then be restored as in the previous scenario): $ git reset -hard HEAD~1 You made a commit deleting a file, but then realized you wanted to keep the file around after all? Do a reset to go back to the state before your commit ( be careful: the "-hard" option means the command will discard changes to tracked files after the specified commit - you can also leave this option out in which case the file deletion will show up as an unstaged change along with any other changes you’ve made in your working tree. I deleted a file and committed the deletion This will work regardless of whether the deletion was staged or not. So you deleted a file, and immediately realized it was a mistake? This one is easy, just do: $ git checkout HEAD Let’s look at a few ways to restore a deleted file, depending on how convinced you were at the time that you really wanted the file to be deleted! I deleted a file but didn’t commit Short of deleting the entire repository directory (and not having a remote), few operations will result in a state where you’re unable to bring back a file. As long as you’ve committed your work in Git, actually losing a file should be quite rare.
