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

Re: Handling merge conflicts a bit more gracefully..

From
Linus Torvalds <torvalds@osdl.org>
Date
Jun 9, 2005, 04:54 UTC
Message-ID
<Pine.LNX.4.58.0506082145160.2286@ppc970.osdl.org>
In-Reply-To
<7vfyvsuoz3.fsf@assigned-by-dhcp.cox.net>
On Wed, 8 Jun 2005, Junio C Hamano wrote:
Show 9 quoted lines
> >>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:
> 
> LT> Yeah, ok, so the fact that we allow missing things in the
> LT> index (which was debatable to start with) makes for
> LT> exceptions.
> 
> Not just that.  Another big difference is that we allow _extra_
> things in the index in two-tree case (i.e. local additions).
> But I do not think these exceptions are necessarily bad.
Well, they'd be bad in a three-way merge.

The reason they aren't bad in a two-way merge is that you don't commit the result - the commits have been done already.

That's really the big conceptual difference between two-way and three-way: never mind the merge algorithm itself.

(In fact, in many ways, two-way merges are really just the same as a one-way merge, except it now knows where it came from, so it can do sanity checking).

As to working tree changes:
Show 5 quoted lines
> which means we are exactly in the same situation as "merge I and
> M pivoting on H" three-way merge, with a dirty work tree.  Any
> solution and help we would give to the end-user for the
> three-way case would automatically help this two-way case,
> wouldn't it?
Yes.

In fact, there's a fairly simple solution, which is to remove the current check for "verify_uptodate()" and instead replace it with the "update" phase not just writing the file, but actually doing a three-way merge on it.

NOTE! This would not affect the resulting _tree_ in any way at all. It would literally only affect how we write out the working directory. Right now we just fail when the working file isn't up-to-date, and that could be replaced with instead doing a

	merge W I M

where "W" is the working file, "I" is the index file, and "M" is the merge result that we currently just write out directly.

In the special case of I == M, we already do _exactly_ this: we know that since I=M, the merge will be W, so we don't do the update at all.

So in fact, doing a 3-way merge is really a generalization of what we already do, and removes a failure case.

NOTE! This 3way merge is fundamentally _different_ from the 3-way merge that is done by "git-merge-one-file-script" that we already do. _That_ 3-way merge is done not on the working files, but on the results in the trees, while this new 3way merge would be done purely in the working directory (ie it wouldn't make sense without the "-u" flag).

If we do this, I'd personally suggest it be another flag, possibly "-u3" instead of just plain "-u".

		Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 33 in “Handling merge conflicts a bit more gracefully..”
  1. Linus TorvaldsJun 8, 2005
  2. Junio C HamanoJun 8, 2005
  3. Linus TorvaldsJun 8, 2005
  4. Junio C HamanoJun 9, 2005
  5. Linus TorvaldsJun 9, 2005
  6. Junio C HamanoJun 9, 2005
  7. Junio C HamanoJun 9, 2005
  8. Linus TorvaldsJun 9, 2005
  9. Junio C HamanoJun 9, 2005
  10. Linus TorvaldsJun 9, 2005
  11. Junio C HamanoJun 9, 2005
  12. Linus TorvaldsJun 9, 2005
  13. Junio C HamanoJun 9, 2005
  14. 0/3 Handling merge conflicts a bit more gracefullyJunio C Hamano, Jun 9, 2005
  15. 1/3 read-tree.c: rename local variables used in 3-way merge code.Junio C Hamano, Jun 9, 2005
  16. 2/3 read-tree -m 3-way: loosen index requirements that is too strict.Junio C Hamano, Jun 9, 2005
  17. 3/3 read-tree -m 3-way: handle more trivial merges internallyJunio C Hamano, Jun 9, 2005
  18. Linus TorvaldsJun 9, 2005
  19. Junio C HamanoJun 9, 2005
  20. Linus TorvaldsJun 9, 2005
  21. Junio C HamanoJun 9, 2005
  22. Add git-diff-stages command.Junio C Hamano, Jun 9, 2005
  23. Linus TorvaldsJun 9, 2005
  24. diff-stages: unuglify the too big main() function.Junio C Hamano, Jun 11, 2005
  25. Junio C HamanoJun 10, 2005
  26. Herbert XuJun 18, 2005
  27. Linus TorvaldsJun 18, 2005
  28. Jeff GarzikJun 9, 2005
  29. Linus TorvaldsJun 9, 2005
  30. read-tree.c: rename local variables used in 3-way merge code.Junio C Hamano, Jun 9, 2005
  31. Handle entry removals during merge correctly.Junio C Hamano, Jun 9, 2005
  32. read-tree -m 3-way: loosen an index requirement that was too strict.Junio C Hamano, Jun 9, 2005
  33. read-tree -m 3-way: handle more trivial merges internally.Junio C Hamano, Jun 9, 2005

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.