Git rebase子树 [英] Git rebase subtree
问题描述
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ (WIP2)
(X)\
o - o(WIP3)$
/ /
o - o - o - o - o - b $ b
是否有一个git命令创建一个新分支,以便它包含分支X之后的子树?我想要执行一个大的rebase,我想要三个WIP分支在基础上重新设计。
我知道我可以通过一些Bash脚本来做到这一点,但我希望要知道如何使用git命令来做到这一点。
没有单一的git命令。你将不得不做一些手动工作。在你的情况下:
$ $ p $ $ $ $ $ $ $ $ $ $ $ $
X - o - o - B - o - o(WIP2)
\
o - o(WIP3)
您首先将WIP1重定位到master:
git rebase --onto master X WIP1
会导致这种情况:
o - o(WIP1)
(master)/
o - o - o - B'
/
/
X - o - o - B - o - o(WIP2)
\
o - o(WIP3)
如果您现在运行 git rebase --onto master X WIP2
,你会得到这样的结构:
o - o(WIP1)
(master)/
o - o - o - B'
/ \
/ o - o - B'' - o - o(WIP2)
/
X - o - o - B - o - o(WIP3)
这是可能不是你想要的,所以现在你已经拥有了d rebase WIP2和WIP3在 B'
:
git rebase - 到B'B WIP2
git rebase --to B'B WIP3
这将导致到:
o - o(WIP1)
(master)/
o - X - - - - - B' - o - o(WIP2)
\
o - o(WIP3)
Suppose I have the following scenario:
o (master)
/ o--o (WIP1)
/ /
o--o--o--o--o--o (WIP2)
(X) \
o--o (WIP3)
Is there a git command which creates a new branch so that it contains the subtree after branch X? I want to perform a "large rebase", I want the three WIP branches rebased on master.
I know I can do that with some Bash scripting but I'd like to know how to do that using a git command.
There is no single git command for that. You will have to do some manual work. In your situation:
o (master)
/ o--o (WIP1)
/ /
X--o--o--B--o--o (WIP2)
\
o--o (WIP3)
You first rebase WIP1 onto master:
git rebase --onto master X WIP1
which will lead to this:
o--o (WIP1)
(master) /
o--o--o--B’
/
/
X--o--o--B--o--o (WIP2)
\
o--o (WIP3)
If you now run git rebase --onto master X WIP2
, you get this structure:
o--o (WIP1)
(master) /
o--o--o--B’
/ \
/ o--o--B’’--o--o (WIP2)
/
X--o--o--B--o--o (WIP3)
This is probably not what you want, so now you should rebase WIP2 and WIP3 on B’
:
git rebase --onto B’ B WIP2
git rebase --onto B’ B WIP3
which will lead to this:
o--o (WIP1)
(master) /
o--X--o--o--B’--o--o (WIP2)
\
o--o (WIP3)
这篇关于Git rebase子树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!