When merging two branches together that results in 1000+ conflicts (the branches have diverged a lot), what is the best practice for being able to divide that work up among a team of people?
Say the code base is in a Visual Studio solution comprising of 20 projects, it would make sense for each team member to merge a project at a time, resolve the conflicts then commit and push to a remote so that the other team members can get the merge work that has been completed.
Here's a scenario:
So, you have the following branches, right?
--o--o--------------o-----o--------o--------o master
\ / / / /
\ / / / /
o--o--o--o--o--o--o--o--o--o--o--o--o--o--o A
\
\
o--o--o--o--o--o--o--o--o--o B
I interpret the description up till (not including) "push the Project1 files into B" as approximately the following git commands:
cd /the/source/project1
get checkout -b project1.B_submerge B
git merge A
# Fix the conflicts
git add $the_modified_files_in_project1
git commit -m "Merge of branch A into project1"
At this point you want to merge the branch project1.B_submerge
to B
without carrying on the "something is merged from A" property that the merge from A
caused (e.g. create the X
version below).
---------o--------o master
/ /
/ /
--o--o--o--o--o--o--o A
\
\
--o--o--o--o--o-----------------X B
\ \ *
\ \ *
o--------o--o project1.B_submerge
This can be done by using the git apply
command.
cd /the/source/project1
git checkout B
git diff B project1.B_submerge | git apply
git add .
git commit -m "Merge of project1.B_submerge using git apply"
The git apply
command takes a patch and applies to the the current branch, and by feeding it the diff from the current branch and anything else, it will effectively make the current branch 100% identical with the content of that anything else.
So this will make the content of the B
branch identical to the content of the project1.B_submerge
branch but without any merge references. Notice this will be a single "squashed" commit though.
NB This will completely discard any commits made on B
after the get checkout -b project1.B_submerge B
command. If this is a possibility create a target branch with
git checkout -b target_B $(git merge-base B project1.B_submerge B)
and use that instead of B
in the git apply command section above, followed by a merge or rebase to the tip of B
.