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

Re: inexplicable failure to merge recursively across cherry-picks

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Oct 10, 2007, 15:25 UTC
Message-ID
<alpine.LFD.0.999.0710100808150.3838@woody.linux-foundation.org>
In-Reply-To
<20071010102528.GB20390@lapse.madduck.net>
On Wed, 10 Oct 2007, martin f krafft wrote:
Show 9 quoted lines
> also sprach Linus Torvalds <torvalds@linux-foundation.org> [2007.10.10.0354 +0100]:
> > Cherry-picking is immaterial. It doesn't matter how the changes
> > come into the tree. It doesn't matter what the history is. The
> > only thing git cares about is the content, and the end result.
> 
> This is the part I over-estimated. I thought that Git would figure
> out that commits 1-3 had been merged into the target and thus apply,
> in sequence, only the commits from the source which had not been
> merged.

Yes, *some* SCM's have tried to do that. In particular, the ones that are "patch-based" tend to think that patches are "identical" regardless of where they are, and while re-ordering of them is a special event, it's not somethign that changes the fundamental 'ID' of the patch.

For example, I think the darcs "patch algebra" works that way.

It's a really horrible model. Not only doesn't it scale, but it leads to various very strange linkages between patches, and it fails the most important part: it means that merges get different results just because people are doing the same changes two different ways.

> Many thanks (again), Linus! Looking forward to your next content
> manager; you know, the one with artificial intelligence built in!
> You could call it "wit" :)

Well, the git model is really largely the reverse: the system is supposed to be as *stupid* as humanly possible, but:

 - make it predictable exactly because it's stupid and doesn't do anything 
   even half-ways smart.
   This is part of the "it doesn't matter *how* you got to a particular 
   state, git will always do the same thing regardless of whether you 
   moved an existing patch around or whether you re-did the changes as 
   (possibly more than one) new and unrelated commits".
 - conflicts aren't bad - they're *good*. Trying to aggressively resolve 
   them automatically when two branches have done slightly different 
   things in the same area is stupid and just results in more problems.
   Instead, git tries to do what I don't think *anybody* else has done: 
   make the conflicts easy to resolve, by allowing you to work with them 
   in your normal working tree, and still giving you a lot of tools to 
   help you see what's going on.

So git doesn't try to avoid conflicts per se: the merge strategies are fundamentally pretty simple (rename detection and the whole "recursive merge" thing may not be simple code, but the concepts are pretty straightforward), and they handle all the really *obvious* cases, but at the same time, I feel strongly that anything even half-way subtle should not be left to the SCM - the SCM should show it and make it really easy for the user to then fix it up.

Side note: even with a totally obvious three-way merge, with absolutely zero conflicts even remotely close to each other, you can have the merge algorithm generate a good merge that doesn't actually *work*.

For example, it's happened a few times that one branch renames a structure member name (and changes all the uses) and another branch adds new code that uses the old member name. The end result: the code will *merge* fine, and there are zero conflicts in the content, because all the changes were totally disjoint, but the end result doesn't actually work or even compile!

So no merge strategy is ever perfect. The git approach is to be simple and predictable, and also to make it easy to fix up (ie even if you get the above kind of automatic merge problem, if you catch it in compiling, you can fix it up, and do a "git commit --amend" to fix up the merge itself before you push it out).

			Linus
Previous: David KastrupNext: David Brown
Message 5 of 11 in “inexplicable failure to merge recursively across cherry-picks”
  1. martin f krafftOct 10, 2007
  2. Linus TorvaldsOct 10, 2007
  3. martin f krafftOct 10, 2007
  4. David KastrupOct 10, 2007
  5. Linus TorvaldsOct 10, 2007
  6. David BrownOct 10, 2007
  7. Miklos VajnaOct 10, 2007
  8. Linus TorvaldsOct 10, 2007
  9. Miklos VajnaOct 11, 2007
  10. Sam VilainOct 11, 2007
  11. Linus TorvaldsOct 11, 2007

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.