I have a branch A and two child branches B1 and B2, that were created from it.
If I add single text/code line to a file in branch B1 and commit that change, then add the same line to the same file in branch B2 and then merge B2 into B1, I get no conflict and merge is performed by recursive strategy.
If i add one line in B1 and two lines in B2 (one of them being the same as in B1) and make a merge, then conflict will appear. Is there any possible way to detect that all the changes, that were made in B1, are fully presented in the changes, that were made in B2, when merge confict appears?
I understand why conflict happends in this situation, is there any way to do this merge automatically via custom merge driver or some tools? I want that if all the text/code presented in B2, then no conflict appear and the result merge will be the copy of B2, but if there are differences, then the merge will result in conflict.

- 11
- 2
1 Answers
I understand why conflict happens in this situation, is there any way to do this merge automatically via custom merge driver or some tools?
Yes: you may write a custom merge driver and declare (via .gitattributes
) that files whose names match some pattern are to be merged with your custom merge driver.
I want that if all the text/code presented in B2, then no conflict appear and the result merge will be the copy of B2, but if there are differences, then the merge will result in conflict.
You will need to write the merge driver that provides this action. Your inputs to your merge driver are the merge base file (the copy that is in whatever shared common commit is the ancestor of the B1 commit), the file that is in the B1 commit, and the file that is in the B2 commit. Read the three files and combine the changes however you like: that's the definition of a merge driver.
(Git does not come with additional merge drivers. The git merge-file
command comes close, but you must program it at least a little bit, and then it only does the same things that Git already does, or union
merge, which is not quite what you have asked for. You could write your own merge driver by invoking git merge-file
to see if there is a conflict, and then analyzing the resulting conflict if there is one.)

- 448,244
- 59
- 642
- 775