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?
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.
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.
You can use git diff --name-status, that will show you files that where added, modified and deleted.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With