我经常在分支上有多个分支,而这些分支都希望基于主线。考虑一下:
* (Mainline)
*
*
| * (topicA_Branch3)
| *
| *
| * (topicA_Branch2)
| *
| *
| * (topicA_Branch1)
| *
| *
|/
*
*
Run Code Online (Sandbox Code Playgroud)
我想将所有这三个topicA分支移到主线上。目前,我知道执行此操作的两种方法:
开启后topicA_Branch3,执行命令git rebase Mainline。
一种。在这一点上,我将不得不删除topicA_Branch1并2手动重建现在rebased上正确提交的分支topicA_Branch3。
另一种方法是执行三个单独的命令:
一种。继续时topicA_Branch1,做git rebase Mainline。
b。 git rebase --onto topicABranch1 <topicA_Branch1-old-SHA> topicABranch2
C。 git rebase --onto topicABranch2 <topicA_Branch2-old-SHA> topicABranch3
d。这有点麻烦...
我是否需要一个命令来重新建立分支并为其带来子分支?
需要明确的是,我想结束于此:
* (topicA_Branch3)
*
*
* (topicA_Branch2)
*
*
* (topicA_Branch1)
*
*
* (Mainline)
*
*
*
*
Run Code Online (Sandbox Code Playgroud)
恐怕这很麻烦,我不知道有任何现有的 do it all 命令。但它是可编写脚本的。从第一个插图到第二个插图的命令是
for i in topicA_Branch1 topicA_Branch2 topicA_Branch3
do
git branch $i._OrIg_ $i
done
# First branch directly
git rebase --onto Mainline topicA_Branch1
# Remaining branches
git rebase --onto topicA_Branch1 topicA_Branch1._OrIg_ topicA_Branch2
git rebase --onto topicA_Branch2 topicA_Branch2._OrIg_ topicA_Branch3
Run Code Online (Sandbox Code Playgroud)
确认一切正确后,您可以删除*._OrIg_分支。这样,您只需使脚本保持最新的分支名称和顺序即可。
更新:您可以按顺序创建所有分支的列表
git rev-list --reverse --simplify-by-decoration Mainline..topicA_BranchN \
| git name-rev --stdin --name-only
Run Code Online (Sandbox Code Playgroud)
在这里,您只需要知道最后一个topicA_BranchN分支的名称,例如示例中的 topicA_Branch3 。
| 归档时间: |
|
| 查看次数: |
686 次 |
| 最近记录: |