2015-09-11 26 views
2

我知道关于此主题的几个问题,但我没有发现任何解决此问题的方法。诀窍是我需要从另外两个人之间拉出一个提交。将最新提交分解为多个分支

我的回购协议是这样的:

A - B - C  <- master 
      \ 
      D <- devel 

,我希望它看起来像这样:

C <- feature1 
/
A 
    \ 
    B - D <- feature2 

我知道我大概可以使用rebase这一点,但一年使用Git后我仍然不清楚所有的行话。

回答

1

更新:使用提交散列而不是基本分支。


是的,我会重订。我知道有一种更快捷的方法可以通过“rebase to”来实现这一点,但我总是感到困惑,因为如何才能把它做好。我会做的是创建新的分支与一切,然后删除你不想要的。

基地犯下

你需要的第一件事是为提交答:您会在接下来的步骤中使用此为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标志指示执行“的Intera cive rebase“。这就是为什么你会看到一位编辑。阅读内置说明,根据需要告知自己将来可以做什么。除了重新绑定本地提交以抵御上游更新,我几乎每天都会使用它来重命名提交并将提交合并到一个提交中,然后再将更改推回上游。这是一个非常强大的工具,可以理解并且不那么复杂。

相关问题