In Git, how do you apply a commit of bug fix to the other newer branches?

后端 未结 3 568
花落未央
花落未央 2021-01-06 18:34

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

  (release-to-customerA)
      |
      U               (master)
     /                 


        
3条回答
  •  迷失自我
    2021-01-06 19:26

    Though cherry-picking will work, I'm not sure why you'd want to. It creates duplicate commits, which can cause problems if you ever want to merge. Indeed, this appears to be a case where you want to merge!

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

    Note that I added a branch name bugfixB - this is a very general idea. The commit U should be made on a branch whose purpose is to fix B (it could be several commits). That branch should then be merged into all branches which need the bugfix - in this case, releaseA, releaseB, and master.

     git checkout -b bugfixB 
     # 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
    

提交回复
热议问题