1.查看有哪些大文件

git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -10 | awk '{print$1}')"

2.移除对该文件的引用

git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch 文件/文件夹' --prune-empty --tag-name-filter cat -- --all

3. 回收空间

清理本地仓库中不可到达的对象

git for-each-ref --format=‘delete %(refname)‘ refs/original | git update-ref --stdin
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

#查看大小
git count-objects -vH

4.推送到服务器

清理远程仓库

git push origin --force --all
git remote prune origin

5.清理服务器缓存

sudo su
cd ${gitlab项目部署目录}/git-data/repositories/{待清理的项目地址}
git count-objects -vH   # 此时还是旧的大小
git gc --prune=now  # 清理无效文件
git count-objects -vH  # 此时就和本地一样,从库减小了