使用--ours / - 他们的所有文件解决冲突 [英] Git resolve conflict using --ours/--theirs for all files

查看:282
本文介绍了使用--ours / - 他们的所有文件解决冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法解决所有使用checkout - 我们 - 他们的的文件的冲突?我知道你可以为个人文件做到这一点,但无法找到一个办法。

通过工作目录并通过xargs命令发送输出:

  grep -lr'<<<<<<<< ;<<'。 | xargs git checkout --ours 

  grep -lr'<<<<<<<<<<''。 | xargs git checkout  - 他们的

这是如何工作的: grep 将搜索当前目录中的每个文件()和子目录( -r )标志)查找冲突标记(字符串'<<<<<<<'< / p>

< code& / code>或 - files-with-matches 标志会导致grep仅输出找到该字符串的文件名。扫描在首次匹配后停止,因此每个匹配的文件只输出一次。



匹配的文件名称管理 xargs ,这是一个将管道输入流分离的实用程序转化为 git checkout --ours 或 - 它们的



更多此连结



由于每次在命令行输入它都会非常不方便,如果您发现自己使用它很多,创建一个别名 Bash 是通常的。



这种方法应该至少可以通过Git版本 2.4.x


Is there a way to resolve conflict for all files using checkout --ours and --theirs? I know that you can do it for individual files but couldn't find a way to do it for all.

解决方案

Just grep through the working directory and send the output through the xargs command:

grep -lr '<<<<<<<' . | xargs git checkout --ours

or

grep -lr '<<<<<<<' . | xargs git checkout --theirs

How this works: grep will search through every file in the current directory (the .) and subdirectories recursively (the -r flag) looking for conflict markers (the string '<<<<<<<')

the -l or --files-with-matches flag causes grep to output only the filename where the string was found. Scanning stops after first match, so each matched file is only output once.

The matched file names are then piped to xargs, a utility that breaks up the piped input stream into individual arguments for git checkout --ours or --theirs

More at this link.

Since it would be very inconvenient to have to type this every time at the command line, if you do find yourself using it a lot, it might not be a bad idea to create an alias for your shell of choice: Bash is the usual one.

This method should work through at least Git versions 2.4.x

这篇关于使用--ours / - 他们的所有文件解决冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆