事后从git仓库中修剪二进制数据 [英] Prune binary data from a git repository after the fact

查看:66
本文介绍了事后从git仓库中修剪二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心将一些大型二进制数据提交到一些提交中.从那时起,我更新了.gitignore,并且不再提交那些文件.但是我想回到较旧的提交中,并有选择地从存储库中删除此数据,删除应该位于.gitignore中的几个目录.我不想自己删除提交.

I accidentally committed some large binary data into some commits. Since then I've updated my .gitignore, and those files are no longer being committed. But I'd like to go back into the older commits and selectively prune out this data from the repository, removing a couple directories that should have been in .gitignore. I don't want to remove the commits themselves.

我将如何实现这一目标?我的首选方法是将.gitignore规则追溯应用到旧提交的某种方法...使用此方法的答案通常对其他人也很有用,因为我确定我的问题不是唯一的.无需针对每个用户的唯一目录结构进行大量自定义,也可以将其快速应用于一般解决方案.

How would I go about accomplishing this? My preferred method would be some way to retroactively apply the .gitignore rules to old commits... an answer that uses this method would also be pretty generally useful to others, since I'm sure my problem is not unique. It would also be quick to apply to a general solution, without lots of customization specific to each user's unique directory structure.

这是可能的,或者是我上面建议的简单方法,还是更复杂的方法?

Is this possible, either the easy way I suggest above, or in some more complicated manner?

推荐答案

此答案中的解决方案对我来说非常合适:

The solution in this answer worked perfectly for me:

您还可以使用> bfg repo之类的工具测试清理过程 清洁器,例如此答案:

You can also test your clean process with a tool like bfg repo cleaner, as in this answer:

java -jar bfg.jar --delete-files *.{jpg,png,mp4,m4v,ogv,webm} ${bare-repo-dir};

(除了BFG确保它不会在您的最新消息中删除任何内容 提交,因此您需要删除当前索引中的那些文件,然后 进行干净"的提交.所有其他先前的提交将被清除 BFG)

(Except BFG makes sure it doesn't delete anything in your latest commit, so you need to remove those files in the current index and make a "clean" commit. All other previous commits will be cleaned by BFG)

这篇关于事后从git仓库中修剪二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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