Glam Prestige Journal

Bright entertainment trends with youth appeal.

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 master

I 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.txt

which gave me a hash for the version which had my file: HASH. Which I then used in the following command:

git checkout HASH^ file.txt

Which then gave me the following error:

error: pathspec 'file.txt' did not match any file(s) known to git

Luckily, 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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy