Git:事实之后如何分离出一个功能分支 [英] Git: how to separate out a feature branch after the fact

查看:219
本文介绍了Git:事实之后如何分离出一个功能分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将特征的某些提交从现有分支移动到特征分支中,并将其从当前分支中有效移除 - 就好像该特征是在单独的特征分支中开发的一样?



背景:分支 develop 包含对两个特征A(比如50个提交)和B(10个提交)疯狂混合的提交,因为它们原本应该已经在同一个版本中。现在我们延迟了特征B.因此,我们只想在开发分支中使用特征A,并且新的特征B 包含A或A和B的提交的分支,这样如果我们合并了两个分支,我们就可以得到 develop 分支的当前位置。



一种方法是从 develop featureB 分支c $ c>分支,然后将提交从A反向应用到 develop 。但是,新的开发 featureB 的合并只是A。



另一种方法是将当前的开发重命名为 featureB ,然后樱桃选择所有提交的A转换为新的开发分支。但是,这将有效地修改 develop 的历史,这很麻烦。

有什么更好的方法可以做到这一点?

解决方案

到目前为止,如果您可以管理它,最简洁的方法就是写出正确的历史记录和切换参考。调用你想分割的历史基础 X

  git checkout -b new-develop X 
git cherry-pick [所有功能_A提交]
#根据需要重复樱桃选择,或者如果有太多
,请重新输入git checkout -b new-featureB X
git cherry-pick [所有feature_B提交]
#...



<然后用 git branch -m 强制推送交换名称,并让每个人都根据需要重新提取和重新绑定任何未发布的工作。

其他任何选项都会给你留下一个非常混乱的历史,如果完全有理由避免它,那么没有理由对所有子孙后代进行这样的处理。 避免它,如果由于任何原因沟通是一个问题。



如果你真的不能这样做,那么请参阅@MykolaGurov很好的详细答案






分支结帐-b ...)


How can I move some commits of a feature from an existing branch into a feature branch, and effectively remove them from the current branch - as if the feature was developed in a separate feature branch?

Background: the branch develop contains commits to two features A (say, 50 commits) and B (10 commits) wildly mixed, since they originally should have been in the same release. Now we are delaying feature B. Thus, we want to have only feature A in the develop branch, and a new featureB branch that contains the commits of A or A and B, such that if we merge both branches, we get the current position of the develop branch.

One way to do that would be to create the featureB branch from the current position of the develop branch and then reversely apply the commits from A to develop. But then the merge of the new develop and featureB would just be A.

Another way would be to rename the current develop into featureB and cherry pick all commits of A into a new develop branch. But that would effectively modify the history of develop, which is troublesome.

What is a better way to do that?

解决方案

By far the cleanest method if you can manage it at all is to just write the correct histories and switch refs. Calling the base of the history you want to split X,

git checkout -b new-develop X
git cherry-pick [all the feature_A commits]
# repeat the cherry-pick as needed or convenient if there's too many 
git checkout -b new-featureB X
git cherry-pick [all the feature_B commits]
# ...

then swap names around with git branch -m, force-push, and have everyone refetch and rebase any unpublished work as necessary.

Every other option is going to leave you with a really messy history, and there's no reason to inflict that on all of posterity if it's at all reasonable to avoid it. Do avoid it if for any reason communication is a problem.

If you really can't do that, then see @MykolaGurov's nicely detailed answer.


( branchcheckout -b . . . )

这篇关于Git:事实之后如何分离出一个功能分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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