我只需要一份冲突文件列表。

还有什么比:

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

or:

git ls-files -u  | awk '{print $4}' | sort | uniq

我想我可以为此设置一个方便的别名,但我想知道专业人士是如何做到的。我会用它来写shell循环,比如自动解决冲突等等。也许可以通过插入mergetool.cmd来替换这个循环?


当前回答

也许这已经添加到Git中,但尚未解析的文件在状态消息(Git状态)中列出,如下所示:

#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   both modified:      syssw/target/libs/makefile
#

注意,这是Unmerged paths部分。

其他回答

git status --short | grep "^UU "

Git的状态会在有冲突的文件旁边显示“已修改”,而不是“已修改”或“新文件”等

Git diff——检查

将显示包含冲突标记(包括行号)的文件列表。

例如:

> git diff --check
index-localhost.html:85: leftover conflict marker
index-localhost.html:87: leftover conflict marker
index-localhost.html:89: leftover conflict marker
index.html:85: leftover conflict marker
index.html:87: leftover conflict marker
index.html:89: leftover conflict marker

来源:https://ardalis.com/detect-git-conflict-markers

这里有一个万无一失的方法:

grep -H -r "<<<<<<< HEAD" /path/to/project/dir

如果您尝试提交,并且存在冲突,那么git将为您提供当前未解决的冲突列表……但不是普通的列表。这通常是您在交互工作时想要的,因为当您解决冲突时,列表会变得更短。