Find when a file was deleted in Git

Question

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?

Answer

To show the commits that changed a file, even if the file was deleted, run this command:

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:

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

See also my article: Which commit deleted a file.

Merge, update, and pull Git branches without using checkouts

How to specify the private SSH-key to use when executing shell command on Git?