我试着找一个好的教程来减小仓库的大小,但是没有找到。我应该如何减小我的仓库大小?它大约有10MB,但是Heroku只允许50MB,而且我还没有完成我的应用程序开发。
我已经在.gitignore文件中添加了常见的排除项(log、vendor、doc等)。尽管我只是最近才添加了.gitignore。
我该怎么办?
我已经在.gitignore文件中添加了常见的排除项(log、vendor、doc等)。尽管我只是最近才添加了.gitignore。
我该怎么办?
2021年2月更新,十一年后:新的git maintenance
命令(手册页面)应该取代git gc
,并且可以计划安排执行。
原文: git gc --aggressive
是强制进行修剪过程的一种方法(确保: git gc --aggressive --prune=now
)。您还有其他命令来清理存储库。但是不要忘记,有时仅使用git gc
就可以增加存储库的大小!
它也可以在filter-branch
之后使用,标记要从历史记录中删除的一些目录(进一步节省空间); 参见这里。但这意味着没有人从您的公共存储库拉取。filter-branch
可以在.git/refs/original
中保留备份引用, 因此该目录也可以被清理。
最后,如这个评论和这个问题所述; 清除reflog可以帮助:
git reflog expire --all --expire=now
git gc --prune=now --aggressive
一种更完整、可能更危险的解决方案是从git存储库中删除未使用的对象
git filter-repo
现在(Git 2.24+,2019年第四季度)替代了已过时的 git filter-branch
或 BFG:它是一个基于 Python 的工具,需要先安装。
Joe 建议:# Find the largest files in .git:
git rev-list --objects --all | grep -f <(git verify-pack -v .git/objects/pack/*.idx| sort -k 3 -n | cut -f 1 -d " " | tail -10)
# Strat filtering these large files:
git filter-repo --path-glob '../../src/../..' --invert-paths --force
#or
git filter-repo --path-glob '*.zip' --invert-paths --force
#or
git filter-repo --path-glob '*.a' --invert-paths --force
git remote add origin git@github.com:.../...git
git push --all --force
git push --tags --force
.git
文件夹从1.7GB降至235MB。非常感谢@VonC的建议。 - Chase Florellgit gc
git gc --aggressive
git prune
prune
始终由 gc
运行(默认为 2 周前)。 - Casgit gc --aggressive --prune=now
命令来清理Git仓库并删除不再需要的对象,这样可以同时运行三个指令。 - rahul286bfg -b 100M # To remove all blobs from history, whose size is superior to 100MB
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push origin <your_branch_name> --force
brew
)安装的工具。brew install bfg
这不会影响每个人,但仓库大小变大的半隐藏原因之一可能是Git子模块。
您可能添加了一个或多个子模块,但在某些时候停止使用它,并且一些文件仍然留在.git/modules
目录中。为了赠送冗余的子模块文件,请参见this question。
然而,就像主仓库一样,另一种方法是导航到.git/modules
中的子模块目录,例如执行git gc --aggressive --prune
。
这些对仓库大小应该有很好的影响,但只要您使用Git子模块,例如使用大型库,您的仓库大小就不应该发生 drastical 变化。
.gitignore
文件中添加什么,这里有一个很好的服务网站gitignore.io,可以根据你的开发环境帮助你设置一个好的.gitignore
文件。 - Blairg23