事后从 git 存储库中修剪二进制数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4565057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Prune binary data from a git repository after the fact
提问by Myrddin Emrys
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,并且不再提交这些文件。但是我想回到旧的提交并有选择地从存储库中删除这些数据,删除应该在 .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.
我将如何实现这一目标?我的首选方法是将 .gitignore 规则追溯应用于旧提交的某种方式......使用这种方法的答案对其他人也非常有用,因为我确信我的问题不是唯一的。也可以快速应用于通用解决方案,无需针对每个用户的独特目录结构进行大量定制。
Is this possible, either the easy way I suggest above, or in some more complicated manner?
这可能是我上面建议的简单方法,还是更复杂的方法?
回答by Ed.
The solution in this answerworked perfectly for me:
这个答案中的解决方案对我来说非常有效:
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};
(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)
您还可以使用bfg repocleaner 之类的工具测试您的清理过程,如以下答案所示:
java -jar bfg.jar --delete-files *.{jpg,png,mp4,m4v,ogv,webm} ${bare-repo-dir};
(除了 BFG 确保它不会删除您最新提交中的任何内容,因此您需要删除当前索引中的那些文件并进行“干净”提交。所有其他以前的提交将由 BFG 清除)