Reputation: 509
When I run git log
, I can see a commit that I created a few days ago, which contains changes to some file (let's call it x.txt
).
However, when I run git log -p x.txt
, which should show me the git changes on this file, I can't see the commit in question.
How could this situation be explained?
Upvotes: 1
Views: 556
Reputation: 1323953
git log -p
uses actually a git diff
option (--patch
)
If git log -- x.txt
doesn't show at all the expected commit, then it simply means that commit didn't introduced any diff for that file.
A git diff -- x.txt
for that commit would be empty.
After extensive discussion, this work (which would mean x.txt
was renamed or moved at some point):
git log --follow -M -p -- x.txt
There is another case where git log -p -- x.txt
wouldn't include a commit:
That -p
option will compare a commit with the previous one for a given file, unless that file was created (in which case, there is no previous commit for that file)
That means a git log -p -- x.txt
won't include the first commit, when the file was initially added.
That "diff" would simply be the full content of x.txt
.
In the OP Yarin Gold's case, though:
git show <expected_commit_SHA> -- x.txt
returns the expected diffgit show --pretty="format:" --name-only <expected commit>
does list x.txt
* (as in /…)git diff <expectedcommit~1> <expectedcommit> -- x.txt
returns (again) the expected changeAll that with a git version 1.9.3 (Apple Git-50) on OS X (10.9.5).
Upvotes: 2