Friday, April 4, 2014

Locate deleted files in git

Problem

You want to undelete the file you removed from git long ago but don't remember the path or the actual file name.

Solution

Use git log to search for deleted file.  Then use another git log command to find all checkins related to this file.

Example

git log --diff-filter=D --summary | grep delete >/tmp/out.txt

Search for the full paths of the files you want to recover from /tmp/out.txt

git log --all -- path/to/file

It will show you all commits that touched the file.