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

Re: Improving merge of tricky conflicts

From
Jeff King <peff@peff.net>
Date
Jul 22, 2020, 07:45 UTC
Message-ID
<20200722074530.GB3306468@coredump.intra.peff.net>
In-Reply-To
<4df975f0-e4b1-afa1-cac1-f38e6d31a0d8@kdbg.org>
On Wed, Jul 22, 2020 at 07:50:08AM +0200, Johannes Sixt wrote:
Show 8 quoted lines
> Am 22.07.20 um 01:29 schrieb B. Stebler:
> > I have been looking for a tool to display merge conflicts, that instead
> > of showing the two versions of the conflicting section, would show the
> > diff for that section in both conflicting commits.
> 
> Perhaps you want to configure `merge.conflictStyle=diff3`? It does not
> exactly show a diff, but it writes the base version of the conflicted
> part in addition to "ours" and "theirs".

Yeah, I find diff3 is usually sufficient. But the contents of the base, "ours", and "theirs" sides are also available in the index:

  # diff between base (stage 1) and ours (stage 2)
  git diff :1:file :2:file
  # diff between base (stage 1) and theirs (stage 3)
  git diff :1:file :3:file

I thought we had added nice aliases for "ours" and "theirs" instead of the hard-to-remember stage numbers, but I think we only did so for things like "git checkout --ours", etc.

The big downside here, of course, is that it's showing the diff for the whole file, not just one hunk (on the other hand, I often find the trickiest conflicts are ones where the changes unexpectedly span multiple hunks).

There's also git-mergetool, which uses the information in those stages to feed content to other tools, which may show conflicts in more advanced ways. I don't have opinions on any of the particular tools it supports, but "git mergetool --tool-help" might be a good place to start exploring.

-Peff
Previous: Johannes SixtNext: Junio C Hamano
Message 3 of 25 in “Improving merge of tricky conflicts”
  1. B. SteblerJul 21, 2020
  2. Johannes SixtJul 22, 2020
  3. Jeff KingJul 22, 2020
  4. Junio C HamanoJul 22, 2020
  5. Jeff KingJul 23, 2020
  6. Junio C HamanoJul 24, 2020
  7. Jeff KingJul 24, 2020
  8. Junio C HamanoJul 24, 2020
  9. Martin von ZweigbergkJan 16, 2021
  10. Jeff KingJan 21, 2021
  11. Martin von ZweigbergkJan 21, 2021
  12. Jeff KingJan 21, 2021
  13. Sergey OrganovJul 22, 2020
  14. Junio C HamanoJul 22, 2020
  15. Sergey OrganovJul 22, 2020
  16. Jeff KingJul 23, 2020
  17. Sergey OrganovJul 23, 2020
  18. Junio C HamanoJul 23, 2020
  19. Jacob KellerJul 24, 2020
  20. Junio C HamanoJul 24, 2020
  21. Sergey OrganovJul 24, 2020
  22. Junio C HamanoJul 24, 2020
  23. Sergey OrganovJul 24, 2020
  24. Junio C HamanoJul 24, 2020
  25. Bono SteblerJul 22, 2020

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.