清除历史记录:在 Git 中将 A 压缩为 B,将 D 压缩为 E
我的仓库有一段丑陋的历史,我想稍微简化一下。根据我的阅读,git rebase 将是我应该使用的工具。我想做的是:
将这个:
A--------------------------I (master)
\ /
B--C-------------G--H--/ (development)
\ /
D--E------/ (feature-1)
\ /
F--/ (feature-2)
变成这样:
A-BCDEFH--I (master)
在提交“I”之后,我有相同形式的其他提交,所以我希望我的最终历史记录看起来像:
A-BCDEFH--I--KLMNO-P (master)
有关如何完成此操作的任何指示?
编辑:请注意,在这个示例中,D 和 F 不是合并提交 - 它们是标准提交,因此它们都不应该从历史记录中消失(尽管合并提交、G 和 I 应该)。
I have an ugly history on my repo and I want to streamline-it a little bit. From what I've read, git rebase would be the tool I should use. What I want to do is:
Turn this:
A--------------------------I (master)
\ /
B--C-------------G--H--/ (development)
\ /
D--E------/ (feature-1)
\ /
F--/ (feature-2)
Into this:
A-BCDEFH--I (master)
After the commit "I", I have other commits in the same form, so I would like my final history to look like:
A-BCDEFH--I--KLMNO-P (master)
Any pointers in how to accomplish this?
EDIT: Please note that in this example, D and F are not merge commits - they are standard commits, so none of them should dissapear from the history (although the merge commits, G and I should).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过以下方式完成第一步:
其中
A
是图中 A 提交的提交标识符。这将创建一个新的分支
new-master
,最终将形成您想要的master
形状(没有引入任何更改的合并提交将从分支中删除)历史)。要移植其他分支,请逐一检查它们并发出 git rebase --onto new-master masterbranchname。当您对更改感到满意时,可以更新
master
分支并删除new-master
:You can accomplish the first step with this:
Where
A
is the commit identifier for the A commit in your graph.This will create a new branch
new-master
that will ultimately wind up in the shape you wantmaster
in (merge commits that introduce no changes of their own will be dropped from the history). To port over the other branches, check them out one-by-one and issuegit rebase --onto new-master master branchname
.When you are satisfied with the changes, you can update the
master
branch and deletenew-master
: