我知道有关该主题的几个问题,但我没有找到任何解决此情况的问题。诀窍是我需要从另外两个提交中取出一个提交。
我的存储库如下所示:
A - B - C <- master
\
D <- devel
我希望它看起来像这样:
C <- feature1
/
A
\
B - D <- feature2
我知道我可能可以使用 rebase
来实现此目的,但使用 Git 一年后我仍然不清楚所有术语。
最佳答案
更新:使用提交哈希而不是基础分支。
是的,我会重新设定基准。我知道有一种更快的方法可以通过“rebase to”来做到这一点,但我总是对如何正确地做到这一点感到困惑。我要做的就是用所有内容创建新分支,然后删除你不想要的内容。
基本提交
您需要的第一件事是提交 A 的提交哈希。您将在接下来的步骤中将其用于 git rebase
。
## Copy the 6-char hex value next to commit "A"
git log --oneline
功能1
git checkout -b feature1 master
# insert the commit hash for commit A
git rebase -i $A
# in the VI editor, delete the line representing commit B, and save
功能2
git checkout -b feature2 devel
# insert the commit hash for commit A
git rebase -i $A
# in the VI editor, delete the line representing commit C, and save
git rebase
上的 -i
标志指示执行“交互式 rebase”。这就是为什么您会遇到编辑器。阅读内置说明,了解将来根据需要可以做什么。除了根据上游的更新重新调整本地提交之外,我几乎每天都使用它来重命名提交并将提交 merge 为一个,然后再将更改推回上游。这是一个非常强大的工具,易于理解,而且实际上并不那么复杂。
关于git - 将最新提交拆分为多个分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32527760/