简体   繁体   English

有没有办法从git历史中删除“无意义”的提交?

[英]Is there a way to remove “pointless” commits from git history?

Suppose I have a git history like this: 假设我有这样的git历史:

A-B-C-D-E-F-G

B added 60k files. B添加了60k文件。

F removed those same files. F删除了那些相同的文件。

Any operation that traverses git history, such as git log , now takes a stupid amount of time if it has to cross F (or B). 任何遍历git历史记录的操作,例如git log ,如果必须越过F(或B),现在需要花费大量的时间。

Is there a way to effectively remove B and F from history, given that they simply cancel each other out? 有没有办法有效地从历史中删除B和F,因为它们只是相互取消了?

More to the point: is there an easy way to do this, and then ensure that the other developers using the repo are also up to date? 更重要的是:是否有一种简单的方法可以做到这一点,然后确保使用回购的其他开发人员也是最新的? (Bear in mind said developers also have feature branches sitting on their machines.) I suspect all the solutions are going to end up resulting in A-C'-D'-E'-G' ... (请记住,开发人员还在其机器上设有功能分支。)我怀疑所有解决方案最终都会导致A-C'-D'-E'-G' ......

My gut says the best I'm going to get is to create a branch from A, cherry-pick C through E, then create a new branch from G, and merge that onto the first branch. 我的直觉说我要得到的最好的是从A创建一个分支,从中选择C到E,然后从G创建一个新的分支,并将其合并到第一个分支上。 Or something. 或者其他的东西。

Just do git rebase -i A and remove the lines for B and F. 只需执行git rebase -i A并删除B和F的行。
But as you said (or meant), this will rewrite published history, so all your fellow developers need to rebase all their branches based off that manipulated branch like described in the man page of git rebase under the section "How to recover from upstream rebase". 但是正如你所说的(或者意味着),这将重写已发布的历史记录,因此所有开发人员都需要根据操作分支重新设置所有分支,如git rebase手册页中“如何从上游rebase恢复”一节所述”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM