threads / discuss / 13666

git and appending merge commits

Subject: git and appending merge commits

## tl;dr

4 messages between May 26, 2008 and May 26, 2008.

replies: 3people: 3as markdown or json

Adam Majer· May 26, 2008, 03:35 UTC · lore
Hi all,

I've recently started using Git and it is a very nice tool. During some merging, I've come upon one type of issue that seems to be a bug somewhere. To reproduce,

  1. branch master
  2. branch upstream
  3. add new version to upstream
  4. merge it to master
  5. append master merge changeset
#5 results in "messsed up" diffs
For an example of such a mess up please see,
http://git.debian.org/?p=collab-maint/mrtg.git;a=commitdiff;h=a8bc78ffd6d51ab09a791fa97e25f57b60eecd06

It appears that the tool generates a patch to a patch and displays that instead of the appended merge diff which is what I would have expected..

Is current output by design?
- Adam

PS. I should have probably used a new commit to do that changelog addition instead of appending the merge!

Shawn O. Pearce· May 26, 2008, 04:51 UTC · re: Adam Majer · lore

Re: git and appending merge commits

Adam Majer <adamm@zombino.com> wrote: ...

Show 12 quoted lines
>   5. append master merge changeset
> 
> #5 results in "messsed up" diffs
> 
> For an example of such a mess up please see,
> 
> http://git.debian.org/?p=collab-maint/mrtg.git;a=commitdiff;h=a8bc78ffd6d51ab09a791fa97e25f57b60eecd06
> 
> It appears that the tool generates a patch to a patch and displays that
> instead of the appended merge diff which is what I would have expected..
> 
> Is current output by design?

Yes, it is by design. This is a feature of Git that very few (if any) other systems have.

What you are seeing here is a combined diff. It is a diff of the final output of the merge against its two parents (the two branches that were merged together). Places where both a "++" or "--" prefix a line indicate a place where the merge commit adds something that is not in either parent. This is stuff that the merge author edited himself/herself during the merge.

If you had not amended the merge, you would have seen a less interesting diff here, as the combined diff output tries to avoid showing trivial changes.

-- 
Shawn.
Junio C Hamano· May 26, 2008, 04:59 UTC · re: Adam Majer · lore

Re: git and appending merge commits

Adam Majer <adamm@zombino.com> writes:
> Is current output by design?

Yes, it is _very much_ by design and it not "messed up" at all. Look at the output of URL you quoted and notice that you are asking for condensed combined diff ("diff --cc").

For a merge commit with N parents, you can define "a diff for the resulting merge commit" in various ways:

 * You could have a set of diffs between each parent to the merge result.
   You can get this with "git diff-tree -p -m $commit".
 * You could say the first parent is special, and define it as the diff
   between its first parent and the merge result.  You can get this by
   asking "git diff $commit^1 $commit".
 * You can say what non-trivial changes the merge itself did.  This is the
   combined merge and what "git show $commit" (and "git log -p") gives.
Depending on what you want, you can ask these various forms of diffs.

When you are reviewing the changes series of commits introduced to the history (iow, "git log -p"), a single diff between parent and the merge result is not so interesting, primarily because each individual change from commits on each side branch is (or should be) much easier to read and understand, but if a merge needed to do something non-trivial to resolve conficts, you would want to know about it, and that is the reason why --cc format is the default.

In a combined diff, unlike the single column to show "+/-/ " at the beginning for one-parent diff, each parent gets one column. And in a condensed combined diff, a hunk whose result is inherited solely from one parent (iow, a trivial conflict resolution) is removed from the output, so that only a non-trivial conflict resolution that leaves result that is different from all parents are shown.

Adam Majer· May 26, 2008, 06:39 UTC · re: Junio C Hamano · lore

Re: git and appending merge commits

Junio C Hamano wrote:
Show 6 quoted lines
> In a combined diff, unlike the single column to show "+/-/ " at the
> beginning for one-parent diff, each parent gets one column.  And in a
> condensed combined diff, a hunk whose result is inherited solely from one
> parent (iow, a trivial conflict resolution) is removed from the output, so
> that only a non-trivial conflict resolution that leaves result that is
> different from all parents are shown.

Thank you Junio and Shawn for the very clear explanation! Now it makes very good sense why the patch looks so "weird" :) For cases where both branches touch the same file and there is a conflict, this would be very useful indeed.

Cheers, Adam

← back to recent threads