如何将 git 分支拆分为两个分支? [英] How to split a git branch into two branches?
问题描述
我试图帮助一位同事不小心从另一个功能分支创建了一个功能分支,而不是从 master 中创建第二个.这基本上就是我们现在所拥有的......
I'm trying to help out a coworker who accidentally created one feature branch from another feature branch, rather than creating the second one from master. Here is essentially what we have now…
Master ---A---B---C
Foo E---F---F---H
Bar J---K---L---M
这就是我们想要的……
Master ---A---B---C
|
Foo | E---F---F---H
|
Bar J---K---L---M
我想到的一种方法是创建 FooV2 和 BarV2 分支,然后将各个提交挑选到适当的 V2 分支中.但我很好奇,有没有更好的方法来处理这种情况?
One way I thought of would be to create FooV2 and BarV2 branches, and cherry-pick the individual commits into the appropriate V2 branches. But I'm curious, is there a better way to handle this situation?
推荐答案
在我看来,你可以:
git checkout J
git rebase master
我尝试了我的建议,但它不起作用.knittl 的建议不起作用(在我的盒子上).以下是对我有用的方法:
I tried what I suggested and it doesn't work. knittl's suggestion doesn't work (on my box). Here's what did work for me:
git rebase --onto master foo bar
这篇关于如何将 git 分支拆分为两个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!