Working with git – How to Restore a Deleted File
- Find the commit that the file was deleted in
- Checkout the version of the deleted file from the commit just before it was deleted. On other words, the last when when it existed.
- Add the restored file and commit to your repository
- git rev-list -n 1 HEAD — “app3.js”
- git checkout f5394fc841d35f004b368dff438dccf4607e1bec^ — “app3.js”
The “^” character following the commit hash tells git to use the parent of that commit, which in this case would be last commit that app3.js existed in.
As you can see, git status shows us that app3.js is now back and is showing as an unstaged, new file. Just do “git add app3.js” and commit. Victory!