在 Git 中列出冲突文件的最简单方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3065650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the simplest way to list conflicted files in Git?
提问by inger
I just need a plain list of conflictedfiles.
我只需要一个简单的冲突文件列表。
Is there anything simpler than:
有没有比以下更简单的事情:
git ls-files -u | cut -f 2 | sort -u
or:
或者:
git ls-files -u | awk '{print }' | sort | uniq
I guess I could set up a handy alias
for that, however was wondering how pros do it. I'd use it to write shell loops e.g. to auto-resolve conflict, etc. Maybe replace that loop by plugging into mergetool.cmd
?
我想我可以alias
为此设置一个方便的工具,但是想知道专业人士是如何做到的。我会用它来编写 shell 循环,例如自动解决冲突等。也许可以通过插入来替换该循环mergetool.cmd
?
回答by CB Bailey
git diff --name-only --diff-filter=U
回答by cnlevy
git diff --check
git diff --check
will show the list of files containing conflict markers including line numbers.
将显示包含冲突标记(包括行号)的文件列表。
For example:
例如:
> 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
回答by inger
Trying to answer my question:
试图回答我的问题:
No, there doesn't seem to be any simpler way than the one in the question, out of box.
不,似乎没有比问题中的方法更简单的方法了,开箱即用。
After typing that in too many times, just pasted the shorter one into an executable file named 'git-conflicts', made accessible to git, now I can just:
git conflicts
to get the list I wanted.
输入太多次后,只需将较短的粘贴到名为“git-conflicts”的可执行文件中,git 可以访问,现在我可以:
git conflicts
获取我想要的列表。
Update: as Richard suggests, you can set up an git alias, as alternative to the executable
更新:正如理查德所建议的,您可以设置一个 git 别名,作为可执行文件的替代
git config --global alias.conflicts '!git ls-files -u | cut -f 2 | sort -u'
An advantage of using the executable over the alias is that you can share that script with team members (in a bin dir part of the repo).
使用可执行文件而不是别名的一个优点是您可以与团队成员共享该脚本(在 repo 的 bin dir 部分)。
回答by Jones Agyemang
Here is a fool-proof way:
这是一个万无一失的方法:
grep -H -r "<<<<<<< HEAD" /path/to/project/dir
回答by Rafa
git status
displays "both modified" next to files that have conflicts instead of "modified" or "new file", etc
git status
在有冲突的文件旁边显示“两者都已修改”,而不是“已修改”或“新文件”等
回答by mda
git status --short | grep "^UU "
回答by Eric Wang
This works for me:
这对我有用:
git grep '<<<<<<< HEAD'
git grep '<<<<<<< HEAD'
or
或者
git grep '<<<<<<< HEAD' | less -N
git grep '<<<<<<< HEAD' | less -N
回答by Emil Re?a Enriquez
you may hit git ls-files -u
on your command line it lists down files with conflicts
你可能会git ls-files -u
在命令行上点击它列出了有冲突的文件
回答by Patrick O'Hara
Maybe this has been added to Git, but the files that have yet to be resolved are listed in the status message (git status) like this:
也许这已经被添加到 Git 中,但是尚未解析的文件在状态消息(git status)中列出如下:
#
# Unmerged paths:
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: syssw/target/libs/makefile
#
Note that this is the Unmerged paths section.
请注意,这是未合并的路径部分。
回答by Tel
If you attempt to commit, and if there are conflicts, then git will give you the list of the currently unresolved conflicts... but not as a plain list. This is usually what you want when working interactively because the list gets shorter as you fix the conflicts.
如果您尝试提交,并且存在冲突,那么 git 将为您提供当前未解决冲突的列表……但不是一个简单的列表。这通常是交互式工作时您想要的,因为当您修复冲突时,列表会变短。