我只需要一份冲突文件列表。
还有什么比:
git ls-files -u | cut -f 2 | sort -u
or:
git ls-files -u | awk '{print $4}' | sort | uniq
我想我可以为此设置一个方便的别名,但我想知道专业人士是如何做到的。我会用它来写shell循环,比如自动解决冲突等等。也许可以通过插入mergetool.cmd来替换这个循环?
我只需要一份冲突文件列表。
还有什么比:
git ls-files -u | cut -f 2 | sort -u
or:
git ls-files -u | awk '{print $4}' | sort | uniq
我想我可以为此设置一个方便的别名,但我想知道专业人士是如何做到的。我会用它来写shell循环,比如自动解决冲突等等。也许可以通过插入mergetool.cmd来替换这个循环?
当前回答
对我来说,公认的答案并不管用。为了防止捕获
警告:[]中的LF将被CRLF取代。 该文件在您的工作目录中有其原始的行结束符
在Powershell中我使用了这种方法:
git ls-files -u| ForEach{($_.Split("`t"))|Select-Object -Last 1}| get-unique
其他回答
git status --short | grep "^UU "
你可以在命令行上点击git ls-files -u,它会列出有冲突的文件
只需阅读手册页的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
-------------------------------------------------
下面是我用来列出适合bash命令行替换的修改文件
git diff --numstat -b -w | grep ^[1-9] | cut -f 3
要编辑列表,使用$(cmd)替换。
vi $(git diff --numstat -b -w | grep ^[1-9] | cut -f 3)
如果文件名中有空格,则无效。我尝试使用sed来转义或引用空格,输出列表看起来是正确的,但$()替换仍然没有达到预期的效果。
使用git diff,带name-only只显示名称,diff-filter=U只包括'Unmerged'文件(可选地,相对于当前工作目录显示路径)。
git diff --name-only --diff-filter=U --relative