将一个更改合并到Git中的多个分支 [英] Merging one change to multiple branches in Git

查看:106
本文介绍了将一个更改合并到Git中的多个分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于拥有一个主分支(主人)并在主题分支中工作。但我正在研究一个项目,现在有两个主要分支(主和实验),我不确定如何最好地将我的主题分支合并到两个分支中?



这是正确的方式来做到这一点?
$ b

 (master)$ git checkout -b漏洞修复程序
#如果没有人可以让我知道正确的方法。 bug修复
(bug修正)$ git commit -a -m修复bug
(bugfix)$ git checkout master
(master)$ git合并bugfix

(master)$ git checkout bugfix
(bugfix)$ git rebase experimental
(bugfix)$ git checkout experimental
(experimental)$ git merge bugfix

$ b

谢谢。

解决方案

Don不要做重新设定,你就定了。只需将您的 bugfix 分支合并到您需要的分支中即可。

  )$ git checkout -b错误修正
在这里修正错误
(错误修复)$ git commit -a -m'修正错误'
(错误修正)$ git checkout master
(master)$ git merge bugfix
$ b $(bugfix)$ git checkout experimental
(experimental)$ git merge bugfix

在进行rebase时,您正在创建一个类似于已经合并的提交的提交,但不同。执行checkout + merge之后进行rebase基本上等同于选择bug修复提交。


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.

解决方案

Don't do the rebase and you're set. Simply merge your bugfix branch into each branch you need it

(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.

这篇关于将一个更改合并到Git中的多个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆