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

Re: git merge a b when a == b but neither == o is always a successful merge?

From
Jeff King <peff@peff.net>
Date
Nov 17, 2014, 20:53 UTC
Message-ID
<20141117205304.GA15880@peff.net>
In-Reply-To
<21610.16623.746985.383838@perdition.linnaean.org>
On Mon, Nov 17, 2014 at 01:39:43PM -0500, Daniel Hagerty wrote:
> "git merge b" produces a successful merge, as both branches perform
> the "same" work.

Just to be clear, you were expecting "git merge b" to produce a conflict?

> For the body of content in question, this is a merge conflict.  Git
> seems to have the hard-coded assumption otherwise.  I had to change
> three source files to get the result I expected, and wasn't seeing
> any indications of parameterization.

I can imagine there might be times you would like to notice this case and visit it manually (e.g., even though the conflict would show both sides with the same content, you might want the resolution to take the two sides sequentially, duplicating them). But there are also cases where choosing the new content is helpful (e.g., one side cherry-picks a commit from the other, then later merges; you would not want to see a conflict there).

> Am I missing some means of getting the results I need?  Thanks!

I don't think there is an easy way to get what you want. You would have to write a new merge 3-way strategy that handles this case differently. And most of the file-level heavy lifting in merge strategies is done by the low-level unpack_trees code, which handles this case. From "git help read-tree", which describes the index-level 3-way merge:

  ·   stage 2 and 3 are the same; take one or the other (it makes no
      difference - the same work has been done on our branch in stage 2
      and their branch in stage 3)

So I think you would have to add an option to git to handle this, unless you want to reimplement quite a lot of code in your merge strategy.

-Peff
Previous: Daniel HagertyNext: Daniel Hagerty
Message 2 of 6 in “git merge a b when a == b but neither == o is always a successful merge?”
  1. Daniel HagertyNov 17, 2014
  2. Jeff KingNov 17, 2014
  3. Daniel HagertyNov 17, 2014
  4. Jeff KingNov 21, 2014
  5. Junio C HamanoNov 21, 2014
  6. Daniel HagertyNov 24, 2014

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.