How do I apply a patch to multiple branches?

Let's assume that I am part of a development team and we are all working on different branches from the same project:

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

      

Today I discovered an error in the shared file for Alice and Bob. This is an old mistake.

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

I guess the correct way is to create a patch, which I personally email Alice and Bob: "Hi Alice and Bob, I encountered a bug that appeared on commit 7a6b87f. Please find the patch attached to this email."

The solution seems very simple if there are only three people working on the project. How do I manage it in a larger project with more branches and more developers?

Of course, if I am alone in the project, I can just use this solution .

+4


source to share


4 answers


You can do what David claims, but instead of merging, you can use the command cherry-pick

. Another option using cherry-pick

is to simply push the changes you made to your branch into other branches. Before doing it this way, you need to make sure that the changes in the commit are only for fixing the bug. Then you just go to each of the other branches and git cherry-pick <commit hash>

if there are any conflicts you will have to resolve them. I think this is the correct way to do it, and it seems to me that it is more disgusting.



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

+5


source


you can easily exit this script with

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

      



Then I also like the common ancestor solution:

 for branch in branch1 branch2 branch3; do git checkout $branch && git merge common-ancestor-branch; done;

      

+2


source


I would create a branch from 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 per commit.

+1


source


The mail solution was used before git is implemented by git and ssh exchange methods and can be used to send patches to people for repositories that are not connected to the internet. The easiest way to apply corrections from mail is to write them to an mbox file and use git am

. But since most people don't even know what an mbox file is, this method isn't used very often.

Mark git help merge-base

to find the point where you want to detach the fixing pin.

If you really want to fix in one commit, you can just write what to commit anywhere and cherry-pick

for all branches, as long as you have write access to those branches.

In large teams, it is enough for each developer to seriously define a common base to merge regularly.

+1


source







All Articles