3

I currently have imported a huge project from SVN to Git. I decided to flatten out all branches and keep only 2. Master branch and Diverged branch.

Master: A-B-C-D
               \ X-Y: Bugfix

Diverged: E-F-G-H

The diverged contains a lot of different source code, but some parts still originate from master. When we have to do some bugfixing we have to manually patch Master and Diverged on SVN. I would like to merge Bugfix into master (no problem here) and merge Bugfix into Diverged.

Keep in mind that i dont want the previous commits to be inserted into Diverged from master. So ABCD should be ignored. The structure im looking for is this:

Master: A-B-C-D-X-Y

Diverged: E-F-G-H-X-Y

Could anyone help me figure this out?

user229044
  • 232,980
  • 40
  • 330
  • 338
Sam
  • 2,647
  • 2
  • 20
  • 25

2 Answers2

2

Merging diverged branches is always painful.

First of all you have to remember some useful git commands that will help you with a monster merge.

git log HEAD..origin/master - will show you the differences between branches.

If simple git merge origin/master does not work try to split the merge into a series of smaller tasks. I suggest rebasing your diverged branch on top of the current master, so that the changes will be localized:

git rebase remotes/origin/master

You will end up with a boring task of resolving each and every conflict (possibly in many commits), but these small tasks are much simpler then dealing with the whole merge at once.

Master: A-B-C-D-X-Y
Diverged: E-F-G-H-X-Y

git checkout diverged
git rebase master

After rebasing is complete you can fast-forward your master to the tip of the branch:

Master: A-B-C-D-X-Y
                  \ E-F-G-H

Empty commits will be omitted. In the most complex scenarios you can use interactive rebase on your branch to rearrange the commits. I.e, for your scheme:

Though it is manual work but it is still a divide-and-conquer tactic.

Read this post for some in-depth ideas: http://blog.springsource.org/2010/12/21/git-and-social-coding-how-to-merge-without-fear/

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
1

Your example can easily solved by git cherry-pick (apart from merge conflicts).

It copies a commit, and applies that to another branch.

git checkout diverged
git cherry-pick X Y

This creates exactly the situation you described in your example, but it's not actually merging anything.

Ikke
  • 99,403
  • 23
  • 97
  • 120