git git合并,保留两者

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13263902/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:43:30  来源:igfitidea点击:

git merge, keep both

gitgit-merge

提问by Steven Penny

For merging I use this to "keep mine"

为了合并,我用它来“保留我的”

git merge -X ours foo

and this for "keep theirs"

这是为了“保留他们的”

git merge -X theirs foo

However on my latest merge it looks best to keep both sides. Does Git have a "strategy" for this, to avoid manually editing the file?

但是,在我最近的合并中,最好保留双方。Git 是否为此制定了“策略”,以避免手动编辑文件?

采纳答案by Dwight Holman

There is no 'merge strategy' for resolving these conflicts.

没有解决这些冲突的“合并策略”。

However, if you truly want a conflict like:

但是,如果您真的想要这样的冲突:

<<<< ours
Foo
=========
Bar 
>>>> theirs

to resolve to

解决

Foo
Bar

then you can configure the 'merge driver'. From the gitattributesman page:

然后您可以配置“合并驱动程序”。从gitattributes手册页:

union

Run 3-way file level merge for text files, but take lines from both versions, instead of leaving conflict markers. This tends to leave the added lines in the resulting file in random order and the user should verify the result. Do not use this if you do not understand the implications.

联盟

为文本文件运行 3 路文件级合并,但从两个版本中提取行,而不是留下冲突标记。这往往会以随机顺序在结果文件中留下添加的行,用户应该验证结果。如果您不了解其含义,请不要使用它。

Add a line to .gitattributes to use this:

在 .gitattributes 中添加一行以使用它:

*.whatever merge=union

回答by james dupont

What about this one?

这个如何?

grep -v -e'^<<<<<<<' -e '^>>>>>>>' -e'=======' filename.txt > filename.tmp

grep -v -e'^<<<<<<<' -e '^>>>>>>>' -e'=======' filename.txt > filename.tmp

mv filename.tmp filename.txt

mv filename.tmp filename.txt