threads / discuss / 24182

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

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

## tl;dr

4 messages between Jun 24, 2010 and Jun 26, 2010.

replies: 3people: 2as markdown or json

Sabyasachi Ruj· Jun 24, 2010, 04:53 UTC · lore

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.

-- Sabyasachi

Jeff King· Jun 24, 2010, 06:10 UTC · re: Sabyasachi Ruj · lore

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

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
Sabyasachi Ruj· Jun 25, 2010, 05:36 UTC · lore

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

>> 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.

Then I guess having contents of both the files would be an expected behavior. Should I report a bug somewhere? - Sabyasachi

Jeff King· Jun 26, 2010, 05:58 UTC · re: Sabyasachi Ruj · lore

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

On Fri, Jun 25, 2010 at 11:06:46AM +0530, Sabyasachi Ruj wrote:
Show 6 quoted lines
> >> 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.
> 
> Then I guess having contents of both the files would be an expected
> behavior. Should I report a bug somewhere?

I would certainly expect it (at least in the index). Posting here is fine to report, but you may want to repost with a more descriptive subject line and a summary of the issue. That will get the attention of people interested in merge issues.

-Peff

← back to recent threads