Git: combining branches with very different structures

We have a branch called upgrade , which was forked by master 6 months ago. In the upgrade branch, we restructured all projects in maven ( master is ant projects), so the structure of project x in the two branches is completely different.

To restructure projects in maven, we used git mv to save the story. Then we made some code changes in the files on upgrade , because the update process required these changes.

Now I want to combine master into upgrade , preserving the whole structure as it exists in upgrade . How to do it?

I tried using git merge master while on the upgrade branch.

But this does not give me any conflicts with the code changes we made on upgrade ; instead, he gave me conflicts in the property files. (I'm definitely sure about the code changes on upgrade that conflict with master ) - what could be wrong?

+7
source share
1 answer

You want to use our strategy (and not a strategy variant, as indicated in the previous version of this answer); while on upgrade , use git merge -s ours master . According to more details in the git man merge page , this will not attempt to perform the actual merge at all, but just use the tree from the ours side for the result and discard each other side in the merge.

Using a merge with this will contain the whole story, create a merge commit (showing the convergence of the two branches in the story), but use all the files on one side of the merge.

Note that the meaning of “ours” and “them” just depends on which branch you connect to when you start the merge (“merge update into master” or “merge master into upgrade”, which both produce the same final story). "Ours" is the only branch you are standing on, and "them" are those branches that you specify in the merge command. This is explained in more detail in the manpage.

EDIT: As an explanation: you (most likely) did not have conflicts with the code changes that you made because the wizard did not diverge sufficiently from the general code base. By default, git merge uses a three- git merge strategy that takes the last common ancestor of the two sides that you want to merge, and only really looks at the changes regarding this common ancestor. If only one side of the branch is progressing, Git will recognize that all changes there replace the old code (in your case, the master code), and it will simply use the code from upgrade automatically (that is, it resolves the "conflict" automatically).

A conflict that you must resolve manually will only be raised when both sides of the merge have changed from a common ancestor. In this case, Git does not know which side is "better" - perhaps even the two sides must be combined to work. Therefore, the user is prompted to resolve such conflicts.

Note. The answer was updated because I previously misinterpreted the -s and -X options.

+1
source

All Articles