1

Say I have an XML file on master:

<entity>
  <field id="name" type="string"/>
  <field id="tel" type="string"/>
</entity>

Now Jean creates branch J, the purpose of which is to handle the postal address, and Bob creates branch B, the purpose of which is to handle the email address.

So Jean changes the file to:

<entity>
  <field id="name" type="string"/>
  <field id="tel" type="string"/>
  <field id="address" type="string"/>
</entity>

And Bob changes the file to:

<entity>
  <field id="name" type="string"/>
  <field id="tel" type="string"/>
  <field id="email" type="string"/>
</entity>

For the purpose of this question, let’s ignore the accompanying code (Java stuff…).

My question is about the merge of those two evolutions. A simple git merge shows both 3rd <field…> side-by-side, as a conflict on the same line, even though these lines do not share a common ancestor (like, eg., if I had changed the 2nd <field…> differently on both branches).

I would like to automatically obtain a merged file with 4 <field…> lines, without conflicts.

I understand that such a merge would be dangerous as a default because in many cases, this is not safe. But when I know that in my situation it is safe, is there a way to tell git to just take everything that is new from both sides?

Yves
  • 21
  • 1
  • 4
  • as far as i know git has serious troubles handling xml files in automatic merges – LuckAss Aug 24 '16 at 09:14
  • Sure, as most Unix tools do ;-) But let’s assume that in my case it is safe… – Yves Aug 24 '16 at 09:16
  • *"I would like to automatically obtain a merged file with 4 lines, without conflicts."* -- the whole point of merge conflicts and the workflow of resolving them by humans is the impossibility to automatically decide how to merge the changes in situations like the one you describe. – axiac Aug 24 '16 at 09:24
  • 1
    http://stackoverflow.com/a/13264117/4060470 – Anton Kolyaev Aug 24 '16 at 09:34
  • I get that. I’m just wondering if there is some parameter or alternative command, that would give the adequate hint to git; a kind of -Xboth-iff-new… – Yves Aug 24 '16 at 09:35
  • @AntonKolyaev Indeed this could be the answer. This union strategy seems to be a bit naive, though. My idea would be: normal merge if the common ancestor has a corresponding line that has been changed, and union if the data is new (absent from the ancestor). I’ll have to test this strategy :-) – Yves Aug 24 '16 at 09:40
  • Possible duplicate of [git merge, keep both](http://stackoverflow.com/questions/13263902/git-merge-keep-both) – Jeff Puckett Aug 24 '16 at 11:52

0 Answers0