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

Re: show all merge conflicts

From
Jeff King <peff@peff.net>
Date
Jan 28, 2017, 14:28 UTC
Message-ID
<20170128142808.hefnv7r3h6zidobw@sigill.intra.peff.net>
In-Reply-To
<CAAj3zPzO4+9t9_L2OXFmkihw-HwFvzybb7GXs4tTeFRyZHOaNQ@mail.gmail.com>
On Fri, Jan 27, 2017 at 09:42:41PM -0800, G. Sylvie Davies wrote:
Show 14 quoted lines
> Aside from the usual "git log -cc", I think this should work (replace
> HEAD with whichever commit you are analyzing):
> 
> git diff --name-only HEAD^2...HEAD^1 > m1
> git diff --name-only HEAD^1...HEAD^2 > b1
> git diff --name-only HEAD^1..HEAD    > m2
> git diff --name-only HEAD^2..HEAD    > b2
> 
> If files listed between m1 and b2 differ, then the merge is dirty.
> Similarly for m2 and b1.
> 
> More information here:
> 
> http://stackoverflow.com/questions/27683077/how-do-you-detect-an-evil-merge-in-git/41356308#41356308

I don't think that can reliably find evil merges, since it looks at the file level. If you had one hunk resolved for "theirs" and one hunk for "ours" in a given file, then the file will be listed in each diff, whether it has evil hunks or not.

I don't think this is just about evil merges, though. For instance, try:

  seq 1 10 >file
  git add file
  git commit -m base
  sed s/4/master/ <file >tmp && mv tmp file
  git commit -am master
  git checkout -b other HEAD^
  sed s/4/other/ <file >tmp && mv tmp file
  git commit -am other
  git merge master
  git checkout --ours file
  git commit -am merged
  merge=$(git rev-parse HEAD)

The question is: were there conflicts in $merge, and how were they resolved?

That isn't an evil merge, but there's still something interesting to show that "git log --cc" won't display.

Replaying the merge like:
  git checkout $merge^1
  git merge $merge^2
  git diff -R $merge
shows you the patch to go from the conflict state to the final one.
-Peff
Previous: Philip OakleyNext: G. Sylvie Davies
Message 5 of 9 in “show all merge conflicts”
  1. Michael SpiegelJan 27, 2017
  2. Jeff KingJan 27, 2017
  3. G. Sylvie DaviesJan 28, 2017
  4. Philip OakleyJan 28, 2017
  5. Jeff KingJan 28, 2017
  6. G. Sylvie DaviesJan 29, 2017
  7. Michael J GruberFeb 27, 2017
  8. Junio C HamanoFeb 27, 2017
  9. Jeff KingFeb 27, 2017

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.