在Git中,你如何将错误修复提交给其他较新的分支? [英] In Git, how do you apply a commit of bug fix to the other newer branches?
问题描述
如果我有一个包含3个分支的公共Git仓库,如下所示:
If I have a public Git repository that contains 3 branches like the following:
(release-to-customerA)
|
U (master)
/ |
A---B---C---D---E ... S---T
|
(release-to-customerB)
其中提交'B'是原始发行版本并承诺'U'解决了'B'中的一些错误。我想将提交'U'应用于 master 和 release-to-customerB 分支,并且当我下次向客户提供基于提交'D','E',...'T',我希望包含提交'U'。
where commit 'B' was the original release version and commit 'U' resolved some bugs in 'B'. I want to apply the commit 'U' to both master and release-to-customerB branch, and when the next time I deliver a new release to the customers based on the commit 'D', 'E', ... 'T', I want the commit 'U' included. What is the cleanest way to do it?
我知道 git rebase
或 git樱桃采摘
可能会在我的本地存储库中做到这一点,但是当我将重新发布的作品提交给公共存储库时,我会搞砸历史吗?
I know that git rebase
or git cherry-pick
may do the trick in my local repository, but will I screw up the history when I submit the rebased work to the public repository?
感谢您的答案。
Thanks for the answers.
推荐答案
尽管樱桃采摘会起作用,但我不确定为什么你会想。它会创建重复的提交,如果您想合并,可能会导致问题。确实,这似乎是你想要合并的情况!
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
请注意,我添加了一个分支名称bugfixB - 这是一个非常普遍的想法。提交 U
应该在其目的是修复B的分支上进行(可以是多次提交)。然后,该分支应该被合并到所有需要修补程序的分支中 - 在本例中,releaseA,releaseB和master。
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 <SHA1 of B>
# 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
这篇关于在Git中,你如何将错误修复提交给其他较新的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!