Find when a file was deleted in Git

I have a Git repository with n commits.

I have a file that I need, and that used to be in the repository, and that I suddenly look for and think “Oh! Where’d that file go?”

Is there a (series of) Git command(s) that will tell me that “file really_needed.txt was deleted at commit n-13”?

In other words, without looking at every individual commit, and knowing that my Git repo has every change of every file, can I quickly find the last commit that HAS that file, so I can get it back?

8

git log --full-history -- [file path] shows the changes of a file and works even if the file was deleted.

Example:

git log --full-history  -- [file path]

If you want to see only the last commit, which deleted the file, use -1 in addition to the command above. Example:

git log --full-history -1 -- [file path]

See also my article: Which commit deleted a file.

Leave a Comment