dave.st
dave.st

Reputation: 21

Git diff after back and forth merging?

The basis of this question can be like at Finding a branch point with Git?

.-- X -- A -- B -- C -- D -- F  (master) 
.          \     /   \     /
.           \   /     \   /
.             G -- H -- I -- J  (branch A)

So I'm looking for a git diff which includes only commits of G+H+I+J

I'm afraid it is not possible to get it because branchA was merged back to master several times, and master was also merged in to branchA several times.

Upvotes: 2

Views: 1058

Answers (2)

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143229

git diff G J should give you G+H+I+J, but since you're concerned about merging, what you want is probably the diff for G+H+J — excluding merges. I'm afraid you'd need to create a temporary branch and cherry-pick these commits to get the diff you need.

Upvotes: 1

Cascabel
Cascabel

Reputation: 497322

Unfortunately, without creating new commits somehow, this isn't really defined. It's possible that the diff introduced by J doesn't even make sense without what was merged in I, namely B and C.

Assuming that J really is disjoint from B and C, you do need to create new commits somehow in order to get the combined diff, because what you're asking for is impossible (in general) to determine without iteratively applying patches and seeing what the result is. The quickest way to do this, though, is not by cherry-picking. Instead you can take advantage of the fact that rebase by default does not preserve merge commits. Therefore:

# create a temporary copy of branch A
git branch branch-A-tmp branch-A
# rebase that copy in place, thus removing the merge commits
git rebase commit-A branch-A-tmp
# examine the diff
git diff commit-A branch-A-tmp

If the changes made in J are not separable from those in B and C, merged in I, you'll get merge conflicts when rebase attempts to re-apply J, thus indicating that the diff you're asking for is not well-defined. Otherwise, you'll get the diff you're looking for.

Upvotes: 0

Related Questions