git仓库使用很长一段时间后,因为提交次数多了.git目录会越来越大;导致构建检出tag时耗时特别长。

整理了清理git仓库方法

使用bfg工具清理

下载地址:https://github.com/rtyley/bfg-repo-cleaner

使用步骤:

下载bfg,是一个jar文件,需求安装java环境才能执行

清理命令

1
2
# 清理>10M的文件
java -jar bfg-path/bfg.jar --strip-blobs-bigger-than 10M --no-blob-protection your-git-repo-path

进入仓库目录,执行

1
2
cd your-git-repo-path
git reflog expire --expire=now --all && git gc --prune=now --aggressive

漫长的等待过后,推送到远程

1
git push --force

自已的项目可以像这样搞,如果是多人使用的仓库,最好是清理后迁移成一个新仓库,然后所有人重新clone