Git中列出冲突文件的最简单方法是什么?

923
我只需要一个普通的列出冲突文件的列表。
是否有比这更简单的方法:
git ls-files -u  | cut -f 2 | sort -u

或:

git ls-files -u  | awk '{print $4}' | sort | uniq
我想我可以设置一个方便的`alias`来实现这个功能,但是我想知道专业人士是如何做的。我会用它来编写shell循环,例如自动解决冲突等。也许通过插入`mergetool.cmd`来替换该循环?

2
git status就可以了。 - Amruth A
1
在冲突合并会话中,git merge --continue 命令将显示存在冲突的文件列表。 - Jayan
8
git rebase --continue 没有列出冲突,只告诉我需要解决它们 (git 版本 2.21.0) - Gary
如果冲突标记被选中,则似乎所有这些都无效。 - TamusJRoyce
23个回答

-1
只需阅读git状态的man page,并过滤所需内容。
 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
       -------------------------------------------------

-1
Git使用“冲突标记”来标记文件中的冲突,像VS Code这样的集成开发环境会用它们来视觉上突出显示冲突部分。
<<<<<<< HEAD 
original code
======= 
merged code
>>>>>>> merged_branch

你可以使用以下方法找到所有仍然带有冲突标记的文件(即所有你尚未解决冲突的文件):
git check --diff | grep "conflict" 

请注意,只有在您尚未提交文件时(如果您仍在寻找合并冲突,则很可能如此),此方法才有效。

为什么这个被踩了?踩的人在这样做之前真的验证了这个答案的有效性吗? - undefined

-3

正如其他答案中所强调的,我们可以简单地使用命令git status,然后查找列在未合并路径下的文件:


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接