永久清理git中的历史大文件

原文发布于:https://www.chenxublog.com/2019/05/26/remove-git-big-files.html

有写老的git仓库,因为当年的无知,不会用.gitignore,残留下了像debugobj等目录的文件,非常占空间,然后就需要对历史里的各种垃圾进行清理了

第一步当然是打开git bash(linux可以无视)

这里要确定某种文件或某个路径,是你要永久清理掉的

如果是目录,执行:

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch obj/*' --prune-empty --tag-name-filter cat -- --all

如果是某个拓展名的文件,比如lod

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.lod' --prune-empty --tag-name-filter cat -- --all

然后依次执行下面的东西,清理空间就好了:

rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

最后强制覆盖云端推送上去,命令行推送带上--force --all参数就可以了,TortoiseGit参考下面:

git仓库瘦身完成辣

原文地址:https://www.cnblogs.com/chenxuuu/p/11434016.html