如何让git通过将“我们的第一个,然后他们的” [英] How do I get git to resolve merge conflicts by putting "ours first, then theirs"
问题描述
我希望能够通过首先放置我们块,然后放置theirs块来自动解决在同一行添加两个块的冲突。
$ b $因此,而不是像下面这样的冲突:
16:09:44 tims @ firebat〜/ git / merge_conflict_example(master |合并)$ cat test.txt
早上好
晚上好
<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HEAD
g'day
=======
aloha
>>>>>>> branch1
hello
hi
我刚刚得到:
16:09:44 tims @ firebat〜/ git / merge_conflict_example(master)$ cat test.txt
早上好
晚安
g'day
aloha
hello
hi
没有冲突。
我认为可能有类似于 git merge branch1 -X oursthentheirs
我在这里使用的示例可在git@bitbucket.org上获得:abznak / merge_conflict_example.git
很简单。只需将 merge
gitattribute设置为 union
即可。
从 https://git-scm.com/docs/gitattributes :
union
对文本文件运行3路文件级合并,从
版本开始,而不是留下冲突标记。这往往会以随机顺序在结果文件中留下
添加的行,用户应该
验证结果。如果您不了解
的含义,请不要使用它。
例如,我刚刚添加了一个.gitattributes文件包含文本 *。txt merge = union
:
10:58 :21 tims @ thor〜/ git / merge_conflict_example(master)$ cat .gitattributes
* .txt merge = union
然后运行合并:
10:58:26 tims @ thor〜/ git / merge_conflict_example(master )$ git merge origin / branch1
自动合并test.txt
[...]
由'递归'策略合并。
test.txt | 1 +
1文件已更改,1插入(+)
10:58:42 tims @ thor〜/ git / merge_conflict_example(master)$ cat test.txt
good早上
晚上好
g'day
aloha
hello
hi
I would like to be able to automatically resolve "two branches added blocks at the same line" conflicts by putting the "ours" block first, then the "theirs" block.
So instead of a conflict like:
16:09:44 tims@firebat ~/git/merge_conflict_example (master|MERGING) $ cat test.txt
good morning
good evening
<<<<<<< HEAD
g'day
=======
aloha
>>>>>>> branch1
hello
hi
I'd just get:
16:09:44 tims@firebat ~/git/merge_conflict_example (master) $ cat test.txt
good morning
good evening
g'day
aloha
hello
hi
with no conflict.
I figure there might be something like git merge branch1 -X oursthentheirs
The sample I used here is available at git@bitbucket.org:abznak/merge_conflict_example.git
It's easy. Just set the merge
gitattribute to union
.
From https://git-scm.com/docs/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.
For the example, I just added a .gitattributes file containing the text *.txt merge=union
:
10:58:21 tims@thor ~/git/merge_conflict_example (master) $ cat .gitattributes
*.txt merge=union
And ran the merge:
10:58:26 tims@thor ~/git/merge_conflict_example (master) $ git merge origin/branch1
Auto-merging test.txt
[...]
Merge made by the 'recursive' strategy.
test.txt | 1 +
1 file changed, 1 insertion(+)
Which had the desired effect:
10:58:42 tims@thor ~/git/merge_conflict_example (master) $ cat test.txt
good morning
good evening
g'day
aloha
hello
hi
这篇关于如何让git通过将“我们的第一个,然后他们的”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!