如何将一组提交从主数据移动到单独的分支? [英] How can I move a set of commits from master to a separate branch?

查看:120
本文介绍了如何将一组提交从主数据移动到单独的分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列的提交(20+),涉及到一个特殊的功能,我试图从我们的主分支中移除,并进入一个单独的分支。

I have a series of commits (20+) that pertain to a particular feature that I am trying to remove from our master branch and into a separate branch.

我在代表我们最新的稳定版本的提交上有一个标记( rel_2009_07_18 ),所以在master上时,git log rel_2009_07_18 HEAD得到我想要移动到一个单独分支的一组提交。还有一些提交应该保留,但我可以挑选那些,因为它们很少。

I have a tag (rel_2009_07_18) on the commit that represents our latest stable release, so when on master, git log rel_2009_07_18..HEAD gets me the set of commits that I want to move to a separate branch. There are also some commits in this set that should remain, but I could just cherry-pick those as they are few.

我看过git filter-branch,但提交选项提到留下的变化,但删除提交 - 绝对不希望这一点。我也看过git rebase,但也提到了将提交重新应用到上游分支。

I've looked at git filter-branch, but the commit option mentions leaving the changes in but removing the commit -- definitely don't want that. I also looked at git rebase, but that also mentions reapplying the commits to the upstream branch.

将这些提交移动到单独的分支有什么好的选择吗?

Is there a good option for moving these commits to a separate branch?

我不确定这是否是一个可行的选择,以及分布式但小(3个开发人员)环境中的影响。但是,我可以执行以下小改动...

I'm not sure if this is a viable option and the repercussions in a distributed, albeit small (3 developers), environment. But could I perform the following little shift...


  1. 本地将主分支重命名为master_plus_feature(或类似的...)

  2. 从`rel_2009_07_18`标签签出
  3. 从这一点创建一个新的分支主文件
  4. 删除远程分支和重新签名从本地推送

想法和建议?感谢!

推荐答案

您编写要从分支中删除提交。这可能会导致问题,如果'主'分支已发布(当然,提交 rel_2009_07_18 发布后),有人根据您的'主'的工作。但也许这不是你的情况的问题。

You write that you want to remove commits from 'master' branch. This might cause problems if 'master' branch was published (well, commits after rel_2009_07_18 are published), and somebody based their work on your 'master'. But perhaps it is not a problem in your case.

下面的两个解决方案都假设您没有未完成的更改

Both solutions below assume that you don't have uncomitted changes

$ git checkout master
$ git branch separate_branch
$ git reset --hard rel_2009_07_18

现在'master'位于 rel_2009_07_18 标记,'separate_branch'在'master'的位置,最终结果与你提出的步骤完全一样(将'master'重命名为'separate_branch',重新创建'master' rel_2009_07_18 ),唯一的区别是在reflogs中。

Now 'master' is at rel_2009_07_18 tag, and 'separate_branch" is at where 'master' was. The final result is exactly the same as in set of steps you proposed (rename 'master' to 'separate_branch', recreate 'master' at rel_2009_07_18), the only difference is in reflogs.

$ git checkout master
$ git branch separate_branch
$ git checkout rel_2009_07_18 -- .
$ git clean -df
$ git commit -m 'Reverted to state at rel_2009_07_18'

请注意,此解决方案不是t espress!YMMV。

Note that this solution is not tested! YMMV.

这篇关于如何将一组提交从主数据移动到单独的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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