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

Re: Confusion about content of conflicted file after : git remove/add

From
Jeff King <peff@peff.net>
Date
Jun 24, 2010, 06:10 UTC
Message-ID
<20100624061029.GA11020@coredump.intra.peff.net>
In-Reply-To
<AANLkTimqrfeNEmlfHGxWTdLgS7tAMOA66N4nV8b5I8F6@mail.gmail.com>
On Thu, Jun 24, 2010 at 10:23:49AM +0530, Sabyasachi Ruj wrote:
Show 8 quoted lines
> I have asked the question in detail in Stack Overflow.
> http://stackoverflow.com/questions/3100032/git-rename-delete-confusion
> Can anyone here explain that situation. Please also read the comments
> I wrote there.
> 
> I am totally baffled and can't predict what will be the content of a
> file after "git rm and git add" in branch and "git mv" in another
> branch.

Those two actions are the same. So there would be no conflict. But in the situation you gave at stackoverflow, it is not just "git rm and git add" versus "git mv". On one side, you actually change the file entirely (well beyond what any rename detection could guess at, as you rewrite the single line in the file).

So your situation is "moved file" versus "moved and changed file". You get a rename/delete conflict because one side renamed the file, but the other side apparently deleted it (because we cannot link the old "a" to the new "b", as they are too different).

We seem to mark this in the index as:
  1. "a" is totally gone. This makes some sense, as it did go away on
     both sides, but given that it is part of a conflict-causing rename,
     I wonder if it should simply stay.
  2. We mark "b" as unmerged, but only put the "renamed to" entry in
     stage 3. For a pure rename/delete conflict, this makes sense. But
     this _isn't_ purely that. We also add "b" on our branch, so there
     should be a further rename/add conflict, but we never see it. At
     the very least, the new contents of "b" should go into stage 2 of
     the index.

So I think there may be a bug. I don't really see any code in merge-recursive.c to handle conflicts on _both_ sides of a rename, but obviously that is possible here.

-Peff
Previous: Sabyasachi RujNext: Sabyasachi Ruj
Message 2 of 4 in “Confusion about content of conflicted file after : git remove/add”
  1. Sabyasachi RujJun 24, 2010
  2. Jeff KingJun 24, 2010
  3. Sabyasachi RujJun 25, 2010
  4. Jeff KingJun 26, 2010

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.