git merge, keep both

一个人想着一个人 提交于 2019-12-17 10:58:31

问题


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?


回答1:


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 gitattributes man page:

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.

Add a line to .gitattributes to use this:

*.whatever merge=union



回答2:


What about this one?

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

mv filename.tmp filename.txt



来源:https://stackoverflow.com/questions/13263902/git-merge-keep-both

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!