Reputation: 349
I have some curious situation and not undestand it.
When I use git log -p -<n>
I don't see changes what exists in file, but If I try git diff <prev>..<next> <file>
difference exists and shown. Why can it be?
Git diff returns blob numbers index cd785c4..967453b 100644
, what I can do with that?
Can that information be helpful for me?
Upvotes: 1
Views: 1091
Reputation: 488053
When I use
git log -p -<n>
I don't see changes what exists in file, but If I trygit diff <prev>..<next> <file>
difference exists and shown. Why can it be?
This means the commit in question is a merge commit, i.e., a commit with at least two parent IDs. When git log -p
or git show
is showing a merge, their default is to use git's combined diff format.
The precise details of combined diffs are in the documentation under the combined diff format section, but I'll quote from the "diff format for merges" section:
Note that combined diff lists only files which were modified from all parents.
(boldface mine). Suppose, for instance, that you merge branch feature
into branch develop
, and that in develop
, file README
says, in part:
There will be a feature X soon.
Suppose that in feature
, README
says:
Feature X is now supported.
When you merge feature
into develop
, the file README
picks up the change—but the resulting README
exactly matches the version in develop
.
If you now git show
the merge commit (or it comes up in git log -p
), the combined diff compares README
in the merge against README
in the first parent (it's different, it has the "now supported" text when develop
didn't before), then compares README
in the merge against README
in the second parent. The second comparison shows no change since the merge picked up the feature
version, so the combined diff omits file README
.
When you find the first parent ID of the merge, i.e., the commit that was the tip of develop
before the merge, and git diff
that commit against the merge commit, you get a regular (non-combined) diff, and since README
picked up the change, you see the change.
Note that you can use the -m
option to tell things that show merges (git log
and git show
, for instance) to display one diff against each parent, rather than a single combined diff. (For typical two-parent merges, this shows two diffs against the one commit. Internally, these commands generate a fake extra commit to do this. You should not have to know about the internal-only fake commit, but it leaks out in some cases.)
Git diff returns blob numbers
index cd785c4..967453b 100644
, what I can do with that?
See this answer.
Upvotes: 2