git tells me that I Merge conflict, but also tells me that no files need merging

为君一笑 提交于 2019-11-29 03:56:19

I think your mergetool command is wrong. Should be

$ git mergetool

Or

$ git mergetool --tool=kdiff3

If you get stuck with a git command you can always check the manual (git mergetool --help).

More Info: https://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html

I tried

git mergetool .

Seemed to work.

I had this issue even when just running the correct command:

$ git mergetool

It may have something to do with having rerere turned on (see this link [Ed.: link no longer working])

I resolved the issue by creating two aliases in .gitconfig, which kick off mergetool for each conflicted file:

Add this to your .gitconfig

# List conflicted files
list-conflicts = !git ls-files -u | cut -f 2 | sort -u

# Force mergetool to recognize conflicts
force-mergetool = !git list-conflicts | xargs git mergetool

tl;dr By request, here's a brief explanation of what this does:

  • git ls-files -u: after a merge attempt with conflicts, this lists all unmerged files, along with some extraneous information and repetition; if run right after a merge, this is essentially all the files with conflicts
  • | cut -f 2 cuts out the 2nd field of this output, which is essentially the file path
  • | sort -u eliminates duplicates
  • | xargs git mergetool pipes this list of files into the mergetool command, which launches your GUI merge tool (assuming you have one set up)

So you can run the first command if you just want to see the files listed. The second command will pipe those all into your merge tool (you could use merge instead of mergetool if that's your preference).

If you want to try it out on your own before adding an alias, you could just run one of these two commands via the command line:

git ls-files -u | cut -f 2 | sort -u

git ls-files -u | cut -f 2 | sort -u | xargs git mergetool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!