Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

git merge, keep both

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...