git merge, keep both

后端 未结 2 839
庸人自扰
庸人自扰 2020-11-29 08:08

For merging I use this to \"keep mine\"

git merge -X ours foo

and this for \"keep theirs\"

git merge -X theirs foo
<         


        
相关标签:
2条回答
  • 2020-11-29 08:32

    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
    
    0 讨论(0)
  • 2020-11-29 08:40

    What about this one?

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

    mv filename.tmp filename.txt

    0 讨论(0)
提交回复
热议问题