git rebase带分支(整棵树) [英] git rebase with branches (whole tree)
问题描述
我正在尝试将两个独立的提交树连接到一个存储库中.
I am trying to connect two independent commit trees into one repository.
最初我有:
A--B--C--D (master1)
E--F--G--H (master2)
\
I--J (somebranch)
这些树没有公共祖先,并且彼此独立(不同的文件和目录). 我想将master2和somebranch(实际上可能是多个分支)都重新建立到master1上.
These tree have no common ancestor and are independent of each other (different files and directories). I want to rebase both master2 and somebranch (may be multiple branches in fact) onto master1.
使用以下命令仅对单个分支进行基准调整很容易:
It's easy to rebase just single branch with:
#simple reabse:
git checkout master2
git git rebase master1
这会给我:
A--B--C--D (master1)
\
E'--F'--G'--H' (master2)
E--F--G--H
\
I--J (somebranch)
最好,我希望一个命令同时移动两个(或多个)分支,以得到如下结果:
Preferably I would like a single command to move both (or more) branches simultanously, to get result like this:
A--B--C--D (master1)
\
E'--F'--G'--H' (master2)
\
I--J (somebranch)
推荐答案
您可以使用鲜为人知的功能,称为嫁接将历史拼接在一起.
You can use a lesser-known feature called grafts to splice the histories together.
$ echo `git rev-list [E] -1` `git rev-list master1 -1` > .git/info/grafts
$ git filter-branch --tag-name-filter cat master2 [other branches]
或者如果涉及多个分支,并且您不想全部列出它们,则可以执行以下操作:
Or if there are multiple branches involved, and you don't want to have to list them all, you can do:
$ git filter-branch --tag-name-filter cat `git show-ref --heads | awk '{print $2}'`
(有关更多详细信息,请参见 answer 161928 或博客文章或
(for more details, see answer 161928, or blog article or advanced instructions)
这篇关于git rebase带分支(整棵树)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!