1

How to resolve merge conflicts in a git repo in case of evil merges. When we want to resolve conflicts merge we have 4 options:

  1. Accept current change
  2. Accept incoming change
  3. Accept both changes
  4. Do it manually

But in real projects,we need to add new code lines which do not appear in any parent branches(evil merges) I know this is not recommended but sometimes you're forced to introduce something new. What's the best solution/practice to resole conflicts in this case?

Youness
  • 11
  • 2
  • Don't allow such merges onto master / main branch. Instead force the users to rebase / merge master / main onto their branch first, resolve the conflicts there and then do a clean merge onto master / main afterwards. – luk2302 Nov 03 '22 at 23:06
  • 5
    You're misunderstanding the recommendation. If the changes you need to make correctly apply the intent of both incoming changes then that's not an evil merge. Evil merges introduce *unrelated* changes. – jthill Nov 03 '22 at 23:06
  • 2
    I would say that the only "option" to resolve a conflict is 4. Do it manually. The other options 1. 2. 3. are just special cases thereof that happen to be the right thing only in a minority of cases. – j6t Nov 04 '22 at 07:40

1 Answers1

0

The best practice remains to protect integration branches (branches like main, dev or develop)

That forces developer to make pull request/merge request in order to merge their work.
And said work won't be merge if there are any conflict, hence, as commented, the need to rebase locally their branch on top of the fetched updated origin/<integration-branch>: they resolve conflicts locally.
Then force-push their branch again, which update the pull-request/merge-request.

Finally, said request can be accepted automatically (no more conflict).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250