You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何GitHub仍检测已删除大文件?上传代码遇大小限制报错

解决GitHub检测到已删除大文件无法上传的问题

问题原因

虽然你已经从本地目录删除了vendor/firefox/libxul.so,但这个文件还存在于Git的历史提交记录里。Git会追踪所有曾经提交过的文件内容,当你执行git push时,GitHub会校验仓库的完整历史数据,包括那些已经被删除的旧文件,所以会触发100MB的大小限制报错。

解决步骤

第一步:确认文件的历史提交记录

先执行命令查看所有包含这个大文件的提交,方便后续确认操作效果:

git log --all --full-history -- vendor/firefox/libxul.so

方法一:用git filter-repo彻底移除历史中的大文件(推荐)

这是Git官方推荐的安全高效工具,比旧的filter-branch更稳定:

  1. 先安装git-filter-repo(不同系统安装方式不同,比如Ubuntu用apt install git-filter-repo,Mac用brew install git-filter-repo)
  2. 执行命令从所有历史提交中移除目标文件:
    git filter-repo --path vendor/firefox/libxul.so --invert-paths
    
  3. 强制推送到远程仓库(注意:如果是多人协作仓库,一定要提前告知队友同步操作,因为强制推送会覆盖远程历史):
    git push origin --force --all
    

方法二:用git filter-branch重写历史(备选方案)

如果无法安装git-filter-repo,可以用这个旧方法:

  1. 先从缓存中删除文件并提交:
    git rm --cached vendor/firefox/libxul.so
    git commit -m "移除历史中的大文件"
    
  2. 重写所有提交记录,彻底删除文件痕迹:
    git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch vendor/firefox/libxul.so' --prune-empty --tag-name-filter cat -- --all
    
  3. 清理本地Git缓存,释放空间:
    git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
    git reflog expire --expire=now --all
    git gc --prune=now --aggressive
    
  4. 最后强制推送到远程:
    git push origin --force --all
    

预防措施

操作完成后,在仓库根目录创建或修改.gitignore文件,添加一行:

vendor/firefox/libxul.so

如果整个vendor目录都不需要提交,直接写vendor/,这样以后就不会不小心把大文件加入Git追踪了。

内容的提问来源于stack exchange,提问作者Alexander

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 12:18:27