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

Re: Question about git-merge-stupid

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jul 3, 2008, 17:08 UTC
Message-ID
<alpine.LFD.1.10.0807030947360.18105@woody.linux-foundation.org>
In-Reply-To
<20080703123314.GS4729@genesis.frugalware.org>
On Thu, 3 Jul 2008, Miklos Vajna wrote:
Show 13 quoted lines
> 
> I'm trying to understand what is the difference between different merge
> strategies. git-merge-stupid is something I failed to understand from
> the git history/code/documentation, so I'm asking here.
> 
> 1) From git history:
> 
> It seems git-merge-stupid was created by 2276aa6 when Junio renamed
> -resolve to -stupid and let -resolve use read-tree. Actually
> 
>         git show 2276aa6:git-merge-stupid.sh
> 
> says -stupid uses read-tree as well.
I think -stupid should probably be removed.

The history of -stupid is from doing the simple single-tree resolve that git-read-tree can do, but then doing the obvious hack of just trying to pick the base that gives the least number of conflicts.

HOWEVER. 
 - in practice, there's seldom any actual point to it. In 99% of all 
   cases, you only have a single merge base anyway.
 - if you have a workflow that encourages criss-cross merges (which makes 
   the above "in practice" not be true), the common case will be that the 
   merge base doesn't much matter.
 - Counting conflicts by looking at the numbe of files that conflict is a 
   pretty stupid metric anyway. Yes, it's obvious, and yes, I bet there 
   are cases where it does the right thing, but I also bet there are cases 
   where it does the _wrong_ thing - it might pick a merge base with fewer 
   files conflicting, but with harder conflicts.
 - the "recursive" merge strategy simply handles things better. There's 
   not really any reason to use a "pick random merge base that happens to 
   give least conflicts", when the recursive strategy does something much 
   more natural.

So you shouldn't really compare -stupid to -resolve. You should compare -stupid to -recursive, and the latter is simply much better.

> 2) From code:
> 
> It seems -stupid is better than -resolve when there are multiple bases.
Maybe. And maybe not.
Show 6 quoted lines
> $ git merge -s resolve c
> Trying simple merge.
> Merge made by resolve.
> 
> So it seems resolve does not completely fail if there are multiple
> bases, either.

I think -resolve can handle up to 6 bases, or something like that. After that it should fail with a "I cannot read more than 8 trees" or something (eight being the two trees to be merged, plus the six bases).

And with multiple bases, it will already pick the best one on a per-file basis (I think - I should know the threeway merge, but it is pretty confusing code) rather than trying to pick one globally. Not pretty, but it's yet another reason why -stupid is actually stupid, and not worth it.

So -stupid in _theory_ can handle cases that -resolve cannot (more than six bases), but (a) that doesn't happen and (b) you'd be better off with -recursive anyway.

> 3) From documentation:
> 
> Actually -stupid is missing from Documentation/merge-strategies.txt. I
> plan to send a patch to add it, once I understnad what it does. :-)

Well, see above. I think there's a reason why -stupid isn't even worth documenting. It might be better off just removed.

		Linus
Previous: Miklos VajnaNext: Miklos Vajna
Message 2 of 7 in “Question about git-merge-stupid”
  1. Miklos VajnaJul 3, 2008
  2. Linus TorvaldsJul 3, 2008
  3. Remove 'stupid' merge strategy.Miklos Vajna, Jul 3, 2008
  4. Junio C HamanoJul 3, 2008
  5. Miklos VajnaJul 4, 2008
  6. Move 'stupid' merge strategy to contrib.Miklos Vajna, Jul 5, 2008
  7. Move 'stupid' merge strategy to contrib.Miklos Vajna, Jul 5, 2008

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.