How Can We Help?
Reinstating a Deleted File In Git
Scenario
- You are working on a featur branch and delete an existing file
- You continue working on your feature branch
- You realise you should not have deleted the file and want to reinstate it
Solution
$ git log --diff-filter=D --summary
This will list all the commits which have deletions. Find the one containing the file you want to reinstate and copy its commit id. Use it, and the file name (with full path) in the following command:
$ git checkout <<commitId>>~1 <<file_to_reinstate>>
The ~1 is important to append to the commitId. It means get the first grandparent of the commit.
(Visited 103 times, 1 visits today)
Reinstating a Deleted File In Git