从另一个分支上的选定提交创建一个git分支

时间:2010-08-17 01:40:32

标签: git merge rebase git-rebase

我创建了一个主要的“功能”分支并且工作了很长时间。然后,我获取了最新的master分支提交,并重新设置了我的“功能”分支提交。然后我将“功能”合并为主人。但是,我忘了合并并继续进入“功能”分支。我现在想要在新分支中提交这些提交,所以我现在想创建另一个分支“feature_2”,它基于自上次合并到master之后“feature”分支上的提交。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

考虑到:

    自从上次合并到feature 以来,
  • master已经引用了提交
  • 分支只是指针
x--x--x (master)
       \
        y--y--y (feature)

,你可以简单地说:

  • git checkout feature
  • git checkout -b feature2
  • git branch -f feature master
    (自master合并后)feature未提交任何提交
x--x--x (master, feature)
       \
        y--y--y (feature2)

feature不再引用来自master的所有提交(重置为master所在的位置),但现在可以通过feature2访问feature }在被重置为master

之前

OP Chip Castle添加:

  

我有其他3个团队成员从那时起他们的分支合并为master,所以我不想合并我已经合并的相同提交。
  我希望只为我需要的功能提供SHA范围从功能到新分支。有没有办法做到这一点或更好的方式?

所以情况是:

x--x--x--y'--y' (master, updated after a fetch from other repo)
       \
        y'--y'--y--y (feature, with y' being already merged, 
                      and y being the commits I need)

然后你可以简单地在master上重新设置功能:相同的提交将被忽略。

相关问题