Get deleted file back from git

November 13, 2020

How to use git to get a delete file.

Get deleted file back from git

Use Git log to find commit id when the file was delete

git log

Once you know the commit id, you can run the following:

git show <commit_id>:<file> > <file>

In the example commit_id will be c96abeb210c6fc324166bac376a9b0b00e955335 In the example file will be app/controllers/example_controller.rb

Example:

git show c96abeb210c6fc324166bac376a9b0b00e955335:app/controllers/example_controller.rb > app/controllers/example_controller.rb

Search