git 更改分支父级
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13235473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change branch parent
提问by Ivan
Have following branches structure:
有以下分支结构:
master
/ \
BranchA BranchB
But it should be:
但它应该是:
master
/
BranchA
/
BranchB
Could anyone advice how to re-hang BranchB as child of BranchA?
有人可以建议如何将 BranchB 重新挂为 BranchA 的孩子吗?
回答by Wesley Wiser
回答by Michael
git checkout branchB; git rebase branchA;
will do this for you. bear in mind if this has been pushed somewhere else, you'll screw up the history.
会为你做这件事。请记住,如果这被推到其他地方,你会搞砸历史。
回答by WesternGun
I suggest using git rebase -i
(interactive mode) to edit the whole history, which commit you want as the starting point of new branch rebase, the commit message, etc.
我建议使用git rebase -i
(交互模式)编辑整个历史记录,您希望将哪个提交作为新分支 rebase 的起点、提交消息等。
In your case, if you desired situation is:
在您的情况下,如果您想要的情况是:
master
/
BranchA
/
BranchB
but on branchA you already have some commits:
但是在 branchA 上你已经有一些提交:
master
/
BranchA
|
commit A1
|
commit A2
You may want to choose the A1 as starting point of branchB, not A2(the latest, where the HEAD of A is), then git rebase -i
can help.
您可能希望选择 A1 作为分支 B 的起点,而不是 A2(最新的,A 的 HEAD 所在的位置),然后git rebase -i
可以提供帮助。