~ 1 min read

Restore a File Deleted From Git

 git rev-list -n 1 HEAD -- <file_path> 

Which will give you the commit hash and then

 git checkout <deleting_commit>^ -- <file_path> 

Or you can do it in one command using a variable for the filepath

Assuming you are using bash, setup an environment var:

 export gitfile=<file_path> and then 
 git checkout $(git rev-list -n 1 HEAD -- "$gitfile")^ -- "$gitfile" 

You can use

 echo $gitfile 

To make sure that the variable was set correctly.

For other shells you would use it's own mechanism like

 setenv 

etc...

Hope this helps!