Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find when a file was deleted in Git

Tags:

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?

like image 671
JohnMetta Avatar asked Jul 27 '11 04:07

JohnMetta


People also ask

How do you check the history of a file in git?

Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.

Can you see deleted files on GitHub?

If you have committed the deletion and pushed it to GitHub, it is possible to recover a deleted file using the GitHub Web UI. GitHub lets you browse the commit history and explore the project at any point in history, which then allows you to view and download any file.

Does git diff show deleted files?

You can use git diff --name-status, that will show you files that where added, modified and deleted.


1 Answers

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.

like image 83
vogella Avatar answered Sep 27 '22 23:09

vogella