Git 彻底清理大文件
前言
因为错误的操作,git commit 历史里存在未进行任何额外操作的大文件,使得后续的大文件上传,以及普通文件的上传都失败了,始终提示:
remote: error: File src.zip is 210.35 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected.
因此必须彻底删除历史中的大文件。
1.安装git-filter-repo
pip install git-filter-repo
提示没有pip就按照提示先安装pip
2.将 git-filter-repo 添加到系统路径
确认安装路径
ls ~/.local/bin/git-filter-repo
如 /home/ubuntu20/.local/bin/git-filter-repo,再执行(不同路径请对照做相应的修改
echo 'export PATH="/home/ubuntu20/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcecho 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.profile
source ~/.profile
测试命令是否可用
git-filter-repo --version
3. 删除
回到有.git 的工作空间,执行
git filter-repo --path 大文件完整名称 --invert-paths --force
检查清理效果
git log --all --full-history -- src.zip # 应该无输出