I have a branch with a function definition missing but the function is still being used causing a crash. The function definition must have been deleted during a merge. I have do
This leads me to believe that 'git log -p' doesn't show merge changes? How can I get this functionality?
You are correct: by default, git log -p
shows you the merge commit, but does not even attempt to show a diff for it.
As odradek wrote in a comment, adding the -c
option will make git log
show combined diffs. You may also use --cc
(note two dashes for --cc
, vs one dash for -c
) which also shows a combined diff, or -m
, which effectively splits the merge for diff purposes, and shows one diff per parent, against that parent.
These same three options can be used with git show
. For whatever reason, though, git show
defaults to --cc
while git log
defaults to nothing at all.
The difference between the three options is clear only with some merges, and it's a bit tricky to show them. We can, however, say one thing pretty clearly: any combined diff shows only files that differ from all parents. That is, both git show -c
and git show --cc
trim what's shown to try to be helpful. (The --cc
form may trim more than -c
, depending on what there is that can be shown. I do not have a handy example of this, though.)
For example, consider commit 3e5c63943d35be1804d302c0393affc4916c3dc3 in the Git repository for Git. This is a merge (with parents c13c783...
and 20690b2...
, and if we run two separate git diff
commands, we can see that, as compared to its first parent, only two files change:
$ git diff --name-status 3e5c639^1 3e5c639
M builtin/remote.c
M t/t5505-remote.sh
but as compared to its second parent, many files (including those same two) change:
$ git diff --name-status 3e5c639^2 3e5c639 | expand
M .gitignore
M .mailmap
M Documentation/Makefile
A Documentation/RelNotes/2.12.0.txt
M Documentation/SubmittingPatches
A Documentation/asciidoctor-extensions.rb
M Documentation/blame-options.txt
M Documentation/cat-texi.perl
M Documentation/config.txt
M Documentation/diff-config.txt
[snipped here - but the same two files do appear in the 339-entry list]
If I run git show --cc
on this, I get no diff listing at all; if I run git show -c
on it, I get a diff listing for builtin/remote.c
and for t/t5505-remote.sh
.
If I run git show -m
on this, I get instead two separate git diff
listings. Neither is a "combined diff". The first starts with:
commit 3e5c63943d35be1804d302c0393affc4916c3dc3 (from
c13c783c9d3d7d3eff937b7bf3642d2a7fe32644)
and shows just the first two files. The second starts with:
commit 3e5c63943d35be1804d302c0393affc4916c3dc3 (from
20690b213975ad3e9b1bc851f434d818bd2d1de9)
and shows all 339 files.
Using -m
is the Really Big Hammer, but you are left with a lot of sorting to do through a lot of pieces. Using --cc
or -c
is usually sufficient.
(Something else that may help, when looking for this sort of change with git log -p
, is to add --full-history
to make sure that git log
follows both branches down each merge. This is only required if you are doing history simplification by adding --
options.)