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

还有什么比:

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

or:

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

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


当前回答

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

其他回答

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

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

注意,这是Unmerged paths部分。

试图回答我的问题:

不,似乎没有比问题中的方法更简单的方法了,开箱即用。

在键入太多次之后,只是将较短的一个粘贴到一个名为“git-conflicts”的可执行文件中,让git可以访问,现在我可以: git冲突来获得我想要的列表。

更新:正如Richard所建议的,你可以设置一个git别名,作为可执行文件的替代

git config --global alias.conflicts '!git ls-files -u | cut -f 2 | sort -u'

通过别名使用可执行文件的一个优点是,您可以与团队成员共享该脚本(在repo的bin dir部分)。

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

如果你在本地git存储库中工作,或者在patch -p1——merge <…是应用。

grep -rnw . -e '^<<<<<<<$'

只需阅读手册页的git状态,并过滤什么是需要的。

 git status --help

代码片段:

       For paths with merge conflicts, X and Y show the modification states of each side of the merge. For paths that do not have merge conflicts, X shows the status of the index, and Y shows the status of the work tree. For untracked
   paths, XY are ??. Other status codes can be interpreted as follows:

   •   ' ' = unmodified

   •   M = modified

   •   A = added

   •   D = deleted

   •   R = renamed

   •   C = copied

   •   U = updated but unmerged

   Ignored files are not listed, unless --ignored option is in effect, in which case XY are !!.

       X          Y     Meaning
       -------------------------------------------------
                [AMD]   not updated
       M        [ MD]   updated in index
       A        [ MD]   added to index
       D                deleted from index
       R        [ MD]   renamed in index
       C        [ MD]   copied in index
       [MARC]           index and work tree matches
       [ MARC]     M    work tree changed since index
       [ MARC]     D    deleted in work tree
       [ D]        R    renamed in work tree
       [ D]        C    copied in work tree
       -------------------------------------------------
       D           D    unmerged, both deleted
       A           U    unmerged, added by us
       U           D    unmerged, deleted by them
       U           A    unmerged, added by them
       D           U    unmerged, deleted by us
       A           A    unmerged, both added
       U           U    unmerged, both modified
       -------------------------------------------------
       ?           ?    untracked
       !           !    ignored
       -------------------------------------------------