Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply a bugfix on multiple branches?

Tags:

git

Suppose I am part of a development team and we all work on different branches from a same project:

     o--o--o--o (Bob)
    /
o--o---o---o---o---o--o (Me, master)
        \
         o--o--o---o (Alice)

Today, I discover a bug in a common file to Alice and Bob. This is an old bug.

How do I fix it in the other branches? What is the workflow in this situation?

I suppose the correct way to proceed is to generate a patch that I personally email to Alice and Bob: "Hi, Alice and Bob, I found a bug that appeared on commit 7a6b87f. Please find the patch attached to this email".

The solution seems to be very simple if there is only three people working on the project. How do I manage it on a bigger project with more branches and more developers?

Of course if I am alone on the project I can simply use this solution.

like image 654
nowox Avatar asked Jun 24 '15 15:06

nowox


3 Answers

You could do what David, states, but instead of merging, you can use cherry-pick command. Another option using cherry-pick is to just cherry-pick the changes that you had made on your branch to the other branches. Before doing that this way you have to be sure that the changes on the commit belong to and only to the bug fix. Then you simply go to each of the other branches and git cherry-pick <commit hash> if there any conflicts you will have to resolve it. That's the right way to do it, I think, I'm doing that way and seems more git-way.

Here the docs: http://git-scm.com/docs/git-cherry-pick

like image 200
xiumeteo Avatar answered Oct 12 '22 14:10

xiumeteo


I would create a branch off of the common ancestor of Alice and Bob, fix the bug there, and then merge that branch into Alice, Bob, and master. This way you only fix the bug once, in a single commit.

like image 45
David Deutsch Avatar answered Oct 12 '22 13:10

David Deutsch


you can easly bash script your way out of this with

for branch in branch1 branch2 branch3; do git checkout $branch && git cherry-pick a970d6ecd; done;

I like the common ancestor solution too then :

 for branch in branch1 branch2 branch3; do git checkout $branch && git merge common-ancestor-branch; done;
like image 39
JuanitoMint Avatar answered Oct 12 '22 13:10

JuanitoMint