In Git, how do you apply bug fixes to other branches?

If I have a public Git repository that contains 3 branches like the following:

(release-to-customerA) | U (master) / | A---B---C---D---E ... S---T | (release-to-customerB) 

where commit "B" was the original release version, and commit "U" resolved some errors in "B". I want to apply the ā€œUā€ commit to the master and release-to-customerB branches, and the next time I put the new version to clients based on commit 'D', 'E', ... 'T', I want to enable commit ' U '. What is the cleanest way to do this?

I know that git rebase or git cherry-pick can do the trick in my local repository, but can I ruin the story when I submit the recovered work to the public repository?

Thanks for answers.

+3
source share
3 answers

Although the cherry will work, I'm not sure why you need it. It creates repeated commits that can cause problems if you ever want to team up. Indeed, this is similar to the case when you want to unite!

  (bugfixB, releaseA) --------------------- Y (master) / / U---X (releaseB) / / / / A---B---C---D---E ... S---T 

Note that I added the bugfixB branch name - this is a very general idea. The end of U must be made on a branch whose purpose is to fix B (this may be several commits). Then this branch should be merged into all branches for which correction is required - in this case release, releaseB and the master.

  git checkout -b bugfixB <SHA1 of B> # fix things, add changes git commit # for each branch... git checkout releaseA git merge bugfixB git checkout releaseB git merge bugfixB git checkout master git merge bugfixB 
+5
source

You do not need to reinstall this specific operation, the selection of cherries is in order:

 git checkout release-to-customerB git cherry-pick U git checkout master git cherry-pick U 

Cherry picker only creates new commits and does not rewrite history, so it is always safe, even if you later click on another repository.

0
source

You should not reinstall this situation, as it is clear that other people saw C commits through T.

As Greg said, you can use git-cherry-pick to get only U; but this will create a new commit with the same different, but with a different identifier. If you want to get all the commits in release-to-customerA in release-to-customerB and master, you can use git-merge like this:

 git checkout release-to-customerB git merge release-to-customerA git checkout master git merge release-to-customerA 
0
source

All Articles