2

[There seems to be a lot of similar information about related topics, but I still cannot find the answer.]

Suppose we have two diverging branches: stable and master (aiming at becoming the next stable):

----> split --> fix 1 -->  [stable]
         \
           ---> development --> more development ----> [master]

The branches diverged, for example, because fix 1 was done differently in master, as some development presented a better way to do it (but the development itself was too large in scope to merge it into the stable branch).

Now we have another bug 2, for which we need fix 2. While the branches are already diverged, the affected files are absolutely the same in both stable in master and the fix would look exactly the same too.

What is the best way to apply identical changes to two diverged branches? Fix in one, then cherry-pick? Or is there a better solution?

2 Answers2

0

Since a merge (merge to stable) is out of question (the dev is too large), that leaves you only with cherry-picking.
(fix in master, cherry-pick in stable)

The only issue is that it introduces a duplicate commit, which might (or not) complicate a future merge from master to stable.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

The problem with cherry-pick is that you don't have an explicit link between both commits, defeating the purpose of keeping track of changes. Just do a merge:

  1. Find an appropriate common ancestor X of master and stable
  2. Create and switch to a branch named fix_bug2 at commit X
  3. Fix bug, commit
  4. Merge fix_bug2 into stable
  5. Merge fix_bug2 into master
coredump
  • 37,664
  • 5
  • 43
  • 77
  • Interesting idea. Can this common-fix branch be local and deleted after merging it into both stable and master? Is it possible to somehow change "branching point" after creating the branch (suppose I made a mistake at determining `X`)? –  Aug 19 '15 at 09:06
  • @doublep Yes, the branch can be local and deleted. The only way to change the branching point is to go back to step 1, deleting your previous attempt, but hopefully the choice should not be difficult to make: you just need a commit where you can write the fix, for example `split`. Then, you *might* still have merge conflicts if the patch cannot be applied exactly as-is in one or both branches. But I would not consider this a mistake. – coredump Aug 19 '15 at 09:48