Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

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?

1 Answer

0 votes
by (50.2k points)

For finding the commit which has the file you need to run this command

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

This shows the changes of a file, works even if the file was deleted.


git log --full-history  -- myfile

If you want to see only the last commit, which deleted a file use -1 also

 git log --full-history -1 -- myfile


Browse Categories