git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: 4-way diff (base,ours,theirs,merged) to review merge results

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 26, 2012, 08:12 UTC
Message-ID
<7vpqd2f1yg.fsf@alter.siamese.dyndns.org>
In-Reply-To
<jicafn$gnj$1@dough.gmane.org>
"Neal Kreitzinger" <neal@rsss.com> writes:
Show 6 quoted lines
> (Combined diff)
> ours:  has line-x
> theirs (master):  does not have line-x
> merged:  has line-x
> merge-base (older master):  *may-or-may-not* have line-x
> conclusion:  I'm not very sure if "merged" should have line-x or not...

When I need this information to resolve a merge in an area of the code that I am not very familiar with, the first thing I do is this:

  $ git merge $other
  $ git diff
  ... yikes, that is a complex conflict!
  $ git checkout --conflict=diff3 $the_path_with_difficult_conflict
  $ git diff
The output will also show the lines from the merge base.

The default style of showing the conflict we use is called the "merge" style (it originally came from the "merge" program of the RCS suite), and it only gives the two sides without the base version. It is sufficient when the person who is making the merge is familiar with the baseline history of the code (e.g. in a contributor-to-integrator pull based workflow, especially when contributors are encouraged to keep their topics focused and short). The "diff3" style that also gives the base version is needed less often in such a setting. That, and also the resulting output is much shorter, is the reason why "merge" style is the default.

When the person who is making the merge is not very familiar with the baseline history (e.g. when using Git as an improved CVS and a contributor pulls the updated upstream into his history), however, "diff3" style may be more often helpful---as you mentioned, "merge" style requires that you know your code well enough to either already know or be able to guess how the version in the merge base looked like, but by definition, pulling the updated upstream into your work will pull more stuff (because many other people are working on the code on the other side) than pulling one topic from a contributor into the integrator tree, so there may be more need to see the version from the merge base in such a workflow.

By setting the configuration variable "merge.conflictstyle" to "diff3", you would get the base version by default whenever there is a conflict.

Previous: Neal KreitzingerNext: Junio C Hamano
Message 2 of 3 in “4-way diff (base,ours,theirs,merged) to review merge results”
  1. Neal KreitzingerFeb 26, 2012
  2. Junio C HamanoFeb 26, 2012
  3. Junio C HamanoFeb 26, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.