Reputation: 43547
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?
Upvotes: 8
Views: 1367
Reputation: 47122
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.
Upvotes: 11
Reputation: 1329492
You need to reset to your merge commit, and redo it, stashing what you want to apply for a later commit.
You can see more at:
That involves a git reset merge_commit_SHA1
, adding only the files which are part of the merge, and stashing the rest.
"Change a deep merge": it describes the case when the merge commit isn't the most recent, which means you need to rebase the other commits done since the merge commit:
git rebase -p --onto $(git rev-parse nonce) HEAD^ $maste
Upvotes: 0