将一项更改合并到 Git 中的多个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7908597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Merging one change to multiple branches in Git
提问by user1015384
I am used to having one main branch (master) and working in topic branches. But I'm working on a project now with two main branches (master and experimental) and I am unsure how to best merge my topic branch into both?
我习惯于拥有一个主分支(master)并在主题分支中工作。但是我现在正在处理一个有两个主要分支(主分支和实验分支)的项目,我不确定如何最好地将我的主题分支合并到两个分支中?
Is this the right way to do it? If not can someone let me know the right way.
这是正确的方法吗?如果没有,有人可以让我知道正确的方法。
(master)$ git checkout -b bugfix
# do bug fix here
(bugfix)$ git commit -a -m 'Fixed bug.'
(bugfix)$ git checkout master
(master)$ git merge bugfix
(master)$ git checkout bugfix
(bugfix)$ git rebase experimental
(bugfix)$ git checkout experimental
(experimental)$ git merge bugfix
Thank you.
谢谢你。
回答by knittl
Don't do the rebase and you're set. Simply merge your bugfix
branch into each branch you need it
不要做rebase,你就准备好了。只需将您的bugfix
分支合并到您需要的每个分支中
(master)$ git checkout -b bugfix
# do bug fix here
(bugfix)$ git commit -a -m 'Fixed bug.'
(bugfix)$ git checkout master
(master)$ git merge bugfix
(bugfix)$ git checkout experimental
(experimental)$ git merge bugfix
When doing the rebase you are creating a commit similar to the already merged commit, but different. Doing the rebase followed by checkout+merge is essentially equivalent to cherry-picking the bug fixing commit.
在执行 rebase 时,您正在创建一个类似于已经合并的提交的提交,但不同。在执行 rebase 之后进行 checkout+merge 本质上等同于挑选错误修复提交。