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

Re: question about a merge result

From
Jeff King <peff@peff.net>
Date
Apr 30, 2009, 15:42 UTC
Message-ID
<20090430154240.GA27416@coredump.intra.peff.net>
In-Reply-To
<38b2ab8a0904300805j5ce19617mdda3254c37d06d38@mail.gmail.com>
On Thu, Apr 30, 2009 at 05:05:19PM +0200, Francis Moreau wrote:
> Well, obviously it's how git works since it's what I got.
Yes, I meant also "this is what it is supposed to do, by design".
Show 7 quoted lines
> But the question was more about if the cortectness of the end result:
> should 'B' removed after the merge.
> 
> IOW if someone works on its own branch remove B file and thought it
> was a bad idea and restore it whereas another person remove B file but
> miss the fact that it was a bad idea, does the merge should silently
> remove B file ?

Yes, it should be removed. And it has nothing to do with removal. Both branches performed some action, but only one reverted it. Thus you still have one branch wanting to make the change, and the other side leaving it alone (in aggregate). So we want to take the changed side.

The only other thing that might make sense would be a conflict (because both sides touched the same area and ended with different results). Git doesn't try to find such a conflict because:

  1. Fundamentally, git cares about endpoints, not changelogs. So by
     design, you can arrive at the same tree state by many different
     routes and the merge will still happen in the same way.
  2. Finding such a conflict in the general case would be quite
     expensive, because you have to track every bit of content changed
     on one branch through every commit on the other branch, to see if
     they ever overlap.
If you want the result of the merge to keep it, you should do one of:
  - revert the removal in _both_ branches
  - merge with "--no-commit", add it back in, and then commit. The
    resulting commit will be a merge commit with the state you specify.
  - merge the early part of one branch, with the removal, into the other
    branch. Then "removed" becomes your basis for comparison, and then
    when you re-merge, the branch that re-adds it will be the only
    change.
-Peff
Previous: Björn SteinbrinkNext: Daniel Barkalow
Message 6 of 7 in “question about a merge result”
  1. Francis MoreauApr 30, 2009
  2. Michael GaberApr 30, 2009
  3. Jeff KingApr 30, 2009
  4. Francis MoreauApr 30, 2009
  5. Björn SteinbrinkApr 30, 2009
  6. Jeff KingApr 30, 2009
  7. Daniel BarkalowMay 1, 2009

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.