Git: merge only the changes made on the branch

元气小坏坏 提交于 2019-12-03 04:53:02

There is no real danger in using cherry-pick, especially if you don't plan on ever merging the release branch into master.

In general, you can prevent problems like these by basing bug fixes on commits that are included in all branches you want to merge the fix into. In the development of git itself, that is achieved by merging all bug fixes into the maint branch (i.e. current stable series which only receives fixes) and then merging that into master periodically. That way, the fix is everywhere and the merges are sane.

This article advises to instead of merging two branches, you would rebase them where git would only rebase non duplicate commits.

But in stead of cherry-picking, you might consider just rebasing the branch:

rebase --onto release B bug

where release is the release branch and bug is the bug branch.

You then get something like

         C'---D' //Bug branch      
        /
       /
  G---H  // Release Branch
 /    
/ 
A---B---E---F---     // master

But this would mean that when you want the bug fixes to be applied to master that you would need to merge bug with master, which causes all the changes in release also to be added to master.

It's up to you to decide what works best for you.

Note that you should not rebase branches that have been pushed to other, because it will create a mess for them.

VonC

Note: as explained above, cherry-picking is acceptable here.
Its main drawbacks are:

In your case:

  • no need to merge back.
  • if you are sure C and D aren't based on code introduced in B, ... cherry-pick them wherever you need them.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!