My repository underwent changes such as:
foo with 100 lines of contentfoo...foo at the top of an existing file bar and git rm foo in the same commitNow I want to see the log of deleted file foo. Everything I've read, including on SO, says I should be able to git log -- foo, but that command produces no output.
If I find the commit that includes deleting foo I can git log 1234abcd -- foo and see its log, so I think my path to foo isn't the problem. Also note that git merge-base HEAD 1234abcd outputs 1234abcd[...], so I think that should prove the commit is reachable from HEAD. Note that there is no file foo in my working tree (obvious, since it was deleted). Using Git 1.7.1.1 on OS X.
Why doesn't git log -- foo work for me and how can I fix it? Thanks!
You can use git diff --name-status, that will show you files that where added, modified and deleted.
Recovering Deleted Files with the Command Line Git provides ways to recover a deleted file at any point in this life cycle of changes. If you have not staged the deletion yet, simply run `git restore <filename>` and the file will be restored from the index.
You can restore a deleted file from a Git repository using the git checkout command. If you do not know when a file was last deleted, you can use git rev-list to find the checksum of the commit in which that file was deleted. Then, you can check out that commit.
You want to use the --follow option on git log, which is described in the man page as:
Continue listing the history of a file beyond renames. Effectively, not only does this allow you to see the history of a renamed file, but this also allows you to view the history of a file no longer in the working tree. So the command you should use should look something like:
git log --follow -- foo Update:
Git 2.9+ has now enabled this by default for all git diff and git log commands:
The end-user facing Porcelain level commands in the "git diff" and "git log" family by default enable the rename detection; you can still use "diff.renames" configuration variable to disable this.
Thanks to x-yuri for the heads up!
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