Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve the same merge conflict in numerous files?

Assume I have this one conflict in 200 files:

<<<<<<< HEAD
/*  Version         1.0.0       */
/*  Date            2017-05-30  */
=======
/*  Version         1.0.1       */
/*  Date            2018-11-30  */
>>>>>>> release/1.0.1

I know for sure that I want the 1.0.1 version in all files. But simply using --theirs for all files is not feasible since I have other modifications too that shall be kept from --ours.

Is there a way to just resolve this one conflict with --theirs and then manually resolve other conflicts (in just a handfull of files) manually?

like image 869
eckes Avatar asked Dec 14 '18 10:12

eckes


People also ask

How do you resolve a merge conflict on the same branch?

To fix this situation, you need to create new commits that mimic those on the branch. The easiest way to do that is with git rebase -f . Now you can merge branch in again.

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.


1 Answers

The only way I can think to make git do what you're asking during conflict resolution, would be to write a custom merge driver that detects and "fixes" the version info before invoking the normal merge-file process. That's doable, but takes a bit of setup (see the git attributes docs under the merge attribute, where it talks about custom merge drivers).

If you can tolerate the extra step, it might be easier to just write a script (something like perl or even awk would be well-suited to the task) that finds and fixes that specific conflict block, and run that script over the conflicted merge output before going on to manually resolve the remaining changes. The biggest down-side to this - and the reason I might consider the merge driver approach - is that if a file conflicts only due to the version block, you'll have no manual work but the file will still be in a conflicted state - so you'll have to check each file to see if there is remaining conflict resolution to be done.

It seems to me it might be wroth revisiting the aspect(s) of your workflow that lead you to expect these conflicts.

like image 84
Mark Adelsberger Avatar answered Nov 09 '22 09:11

Mark Adelsberger