减少 git 存储库大小 [英] Reduce git repository size
问题描述
我试图寻找一个关于减少 repo 大小的好教程,但没有找到.我如何减少我的 repo 大小...大约 10 MB,但问题是 Heroku 只允许 50 MB,而且我还没有完成我的应用程序的开发.
I tried looking for a good tutorial on reducing repo size, but found none. How do I reduce my repo size...it's about 10 MB, but the thing is Heroku only allows 50 MB and I'm no where near finished developing my app.
我已经在 .gitignore 中添加了常见的可疑对象(日志、供应商、文档等).虽然我最近才加了.gitignore.
I added the usual suspects (log, vendor, doc etc) to .gitignore already. Although I only added .gitignore recently.
有什么建议吗?
推荐答案
git gc --aggressive
是强制修剪过程发生的一种方法(可以肯定的是:git gc --aggressive --prune=now代码>).您有其他命令要清理回购也是.但不要忘记,有时
git gc
单独可以 增加仓库的大小!
git gc --aggressive
is one way to force the prune process to take place (to be sure: git gc --aggressive --prune=now
). You have other commands to clean the repo too. Don't forget though, sometimes git gc
alone can increase the size of the repo!
也可以用在filter-branch
之后,标记一些要从历史记录中删除的目录(进一步增加空间);请参阅此处.但这意味着没有人从您的公共回购中提取.filter-branch
可以在 .git/refs/original
中保留备份 refs,这样目录也可以被清理.
It can be also used after a filter-branch
, to mark some directories to be removed from the history (with a further gain of space); see here. But that means nobody is pulling from your public repo. filter-branch
can keep backup refs in .git/refs/original
, so that directory can be cleaned too.
最后,正如本评论中提到的和这个问题;清理 reflog 会有所帮助:
Finally, as mentioned in this comment and this question; cleaning the reflog can help:
git reflog expire --all --expire=now
git gc --prune=now --aggressive
更完整但可能更危险的解决方案是从 git 存储库中删除未使用的对象
An even more complete, and possibly dangerous, solution is to remove unused objects from a git repository
2021 年 2 月更新,十一年后:新的 git maintenance
命令(手册页) 应该取代 git gc
和 可以安排.
Update Feb. 2021, eleven years later: the new git maintenance
command (man page) should supersede git gc
, and can be scheduled.
这篇关于减少 git 存储库大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!