I committed a file to my local git and then pushed it to github.
I performed the following commands to remove that file and then pushed it to github:
git rm file.txt
git commit -m remove file.txt
git push -u github masterI then realized that I want the file back. I tried the instructions outlined here:
I ran the following command:
git rev-list -n 1 HEAD -- file.txtwhich gave me a hash for the version which had my file: HASH. Which I then used in the following command:
git checkout HASH^ file.txtWhich then gave me the following error:
error: pathspec 'file.txt' did not match any file(s) known to gitLuckily, I was able to go to github and recover all of my files from there, but I still don't known how to do it locally, or even if it's possible.
1 Answer
Use git reflog to get the commit hash for the point that had your file. Then use git checkout <hash> to get back to that commit hash.
Alternatively, you can use git checkout HEAD{1} to go back one commit.