I didn't realize I was in the middle of a merge when I wrote a bunch of code. Now git log -p
will not show me the diff of this change (which got auto-committed as a merge commit).
How can I get it to show up in my log diff history?
It's a bit disappointing that Git doesn't show you a patch for merges with -p
. Part of the reason is that the patch produced by -p
is a unified diff, and it's created from one base and one target revision. A merge has two bases, so a unified diff isn't representative of the change that needs to be made.
So there are two ways to get what you want. git log -p -c
will show you N diffs in a merge commit, where N is the number of merge parents. Or, you can use git log -p --cc
and see a more compacted form of the diff. It looks a lot like a unified diff, but can handle the fact that merges have multiple parents. FWIW, --cc
stands for "compact combined". Compact combined output is what you would see if you ran git show SHA1
for the commit in question.
One more small note: if there were no edits where made in a merge commit, then you will not see a diff in the git log -p --cc
output. Also, there's current no way to make a diff show up merge commits by default. You're best bet is to use an alias if you need something short and memorable.
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