合并GIT中合并分支的历史记录?
在我的 git 存储库中,我已将分支“B”合并到“master”中,获得以下结构:
--> A --> B --> C --> D (branch master)
| |
F --> G --> H (branch B)
我现在想要合并分支以获得以下历史记录:
--> A --> B --> F --> G --> H --> D
我该怎么做?
问候, 约亨
In my git repository, I have merged branch "B" into "master", getting the the following structure:
--> A --> B --> C --> D (branch master)
| |
F --> G --> H (branch B)
I now want to combine the branches to get the following history:
--> A --> B --> F --> G --> H --> D
How can I do this?
Regards,
Jochen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设 C 是合并提交,这就是您不希望将其包含在结果中的原因。
您需要做的就是 git rebase
让我们从另一个示意性提交图开始。留下原来的
分支完好无损,我们将在一个名为
rebasing
的新分支上进行操作,只需将
topic
和rebasing
之间的所有内容重新定位到topic
上即可。或者使用更短的命令执行相同的操作
现在,当我们查看
rebase
时,我们有一条从A
到D
的直线。所以,现在唯一的问题可能是顺序与原来的不同
你期望的。您可以通过使用 git rebase 重新排序提交来轻松解决此问题
--interactive,如果你愿意的话。
或者您以稍微复杂的方式重新设置所有内容。让我们重新开始吧。
首先将从
C
到master
(又名D
)尖端的所有内容放在topic
的提示(又名H
):最后一次 rebase,最后,我们就完成了。
瞧!
I assume
C
is a merge commit, and that's the reason you don't want to have it in your result.What you need, to do what you want, is git rebase
Let's start of with yet another schematic commit graph. To leave the original
branches intact we will operate on a new branch called
rebasing
Just rebase everything between
topic
andrebasing
ontotopic
.or do the same with a shorter command
Now when we just look at
rebasing
we have a straight line formA
toD
.So, the only problem right now might be that the order is different from what
you expected. You could easily fix that by reordering commits with
git rebase
, if you want to.--interactive
Or you rebase everything in a slightly more complicated way. Let's start again.
First take everything from
C
to the tip ofmaster
(aka.D
) and put it on thetip of
topic
(aka.H
) :One last rebase, at the end, and we are finished.
Voila!
我将从 A 分支,然后挑选您想要的提交
:
I would branch from A and then cherry pick in the commits that you want
so: