nowox
nowox

Reputation: 29086

How to apply a bugfix on multiple branches?

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.

Upvotes: 9

Views: 4262

Answers (4)

JuanitoMint
JuanitoMint

Reputation: 511

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;

Upvotes: 3

xiumeteo
xiumeteo

Reputation: 961

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

Upvotes: 9

ikrabbe
ikrabbe

Reputation: 1929

The mail solution was used before git implemented git and ssh protocol exchange methods and can be used to send people patches for repositories that are not connected to the internet. The simplest way to apply patches from a mail is to write them into an mbox file and use git am. But as most people don't even know what an mbox file is, that method isn't used quite often.

Check git help merge-base to find a point where to branch off for a fixing commit.

If you really want to fix in a single commit you can just write that commit anywhere and cherry-pick it for all the branches if you have write access to those branches.

In bigger teams it is quite serious for every developer to define a common base, to merge with regularly.

Upvotes: 2

David Deutsch
David Deutsch

Reputation: 19025

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.

Upvotes: 7

Related Questions