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)
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.
2 Solutions collect form web for “Git diff after back and forth merging?”
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.
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
J really is disjoint from
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
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.