将一项更改合并到 Git 中的多个分支
我习惯于拥有一个主分支(master)并在主题分支中工作。但我现在正在开发一个有两个主要分支(主分支和实验分支)的项目,我不确定如何最好地将我的主题分支合并到两个分支中?
这是正确的做法吗?如果没有,有人可以让我知道正确的方法。
(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
谢谢。
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?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要进行变基,你就准备好了。只需将您的
bugfix
分支合并到您需要的每个分支中。在执行 rebase 时,您将创建一个与已合并的提交类似但不同的提交。执行 rebase 后进行 checkout+merge 本质上等同于挑选 bug 修复提交。
Don't do the rebase and you're set. Simply merge your
bugfix
branch into each branch you need itWhen 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.