1

I'm trying to do union merge to a file which contains simple javascript objects. However, I noticed that git merge seems to be "combining" multiple merge conflicts into a single merge conflict if it results into same or lower amount of rows. This basically ruins the possibility for auto-merging with merge=union.

I have a file with the following content:

1: {
  main: '1',
},
2: {
  main: '2',
},
3: {
  main: '3',
},

Lets imagine two branches, which both add content to the end of each object, for example:

1: {
  main: '1',
  branch1: 'x',
},
2: {
  main: '2',
  branch1: 'y',
},
3: {
  main: '3',
  branch1: 'z',
},

If we merge these branches, it produces following merge conflict:

1: {
  main: '1',
<<<<<<< HEAD
  branch1: 'x',
},
2: {
  main: '2',
  branch1: 'y',
},
3: {
  main: '3',
  branch1: 'z',
=======
  branch2: 'q',
},
2: {
  main: '2',
  branch2: 'w',
},
3: {
  main: '3',
  branch2: 'e',
>>>>>>> branch2
},

while I would expect to see something like this:

1: {
  main: '1',
<<<<<<< HEAD
  branch1: 'x',
=======
  branch2: 'q',
>>>>>>> branch2
},
2: {
  main: '2',
<<<<<<< HEAD
  branch1: 'y',
=======
  branch2: 'w',
>>>>>>> branch2
},
3: {
  main: '3',
<<<<<<< HEAD
  branch1: 'z',
=======
  branch2: 'e',
>>>>>>> branch2
},

Diff shows correctly the lines which have been changed between branches, and a workaround would be to add blank lines between the values. Why git decides to combine those merge conflicts into one bigger merge conflict, while git clearly knows that the lines between each object are not changed? Is it possible to turn that feature off, without writing complicated merge adapter?

Myzel
  • 21
  • 2
  • 1
    This is likely because the "hunks" are too close together and git sees it as one change. I do not know how to adjust this. --- (Also, this isn't on-topic, but that's not JSON) – evolutionxbox Feb 22 '21 at 16:39
  • Decreasing the "context" would make merging more difficult or lead to incorrect results. Do the questions and links to [this answer](https://stackoverflow.com/questions/11241758/in-git-how-do-i-increase-the-context-for-merges) provide any useful info to you? Would using "patience diff" help in your case? – knittl Apr 27 '21 at 18:06

0 Answers0