Git:如何在特定提交之前删除历史记录 [英] Git: how to remove history before a specific commit

查看:959
本文介绍了Git:如何在特定提交之前删除历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  root  -  c1  -  c2  -  ..  -  c1000  -  c1001  - c1002  -  ..  -  c2000  -  top 

我想要:

  root = c1000  -  c1001  -  c1002  -  ..  -  c2000  -  top 

p>

如何?



(我想我可以通过 git filter )



(当然我知道这意味着历史重写...)

解决方案

最简单的方法是使用git嫁接。如果您编辑.git / info / grafts文件,您可以将行放入格式文件中。

[ref] [parent1] [ parent2] ...



然后将左侧引用的任何提交视为右侧列出的父代是承诺。因此,您可以插入一行,如

c1000



它会被视为没有父母。然后可以通过运行git-filter-branch来烘焙。


I.e., I have:

root -- c1 -- c2 -- .. - c1000 -- c1001 -- c1002 -- .. -- c2000 -- top

and I want to have:

root = c1000 -- c1001 -- c1002 -- .. -- c2000 -- top

How?

(I guess I can do via git filter-branch, but how exactly?)

(Of course I know that this means history-rewriting...)

解决方案

Easiest way is with a git graft. If you edit the file .git/info/grafts, you can put lines in the file of the format

[ref] [parent1] [parent2] ...

Any commits referenced on the left side are then treated as if the parents listed on the right are the parents of that commit. So you can insert a line like

c1000

and it will be treated as though it has no parents. This can then be "baked in stone" by running git-filter-branch.

这篇关于Git:如何在特定提交之前删除历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆