Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git merge, keep both

Tags:

git

git-merge

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?

like image 408
Zombo Avatar asked Nov 07 '12 05:11

Zombo


People also ask

How do I keep both changes in merge conflict in Visual Studio?

If you need to keep all of your changes to a file, you can right-click it in the Unmerged Changes section and select Keep Current (Local) without having to open Merge Editor.

Why do I keep getting merge conflicts?

Often, merge conflicts happen when people make different changes to the same line of the same file, or when one person edits a file and another person deletes the same file. You must resolve all merge conflicts before you can merge a pull request on GitHub.


2 Answers

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 
like image 176
Dwight Holman Avatar answered Oct 02 '22 11:10

Dwight Holman


What about this one?

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

mv filename.tmp filename.txt

like image 26
james dupont Avatar answered Oct 02 '22 11:10

james dupont