Git推送报错:已删除大文件仍提示超出GitHub文件大小限制求助
问题描述
推送代码时遇到以下错误:
remote: error: File storage/uploads.zip is 620 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
首次推送时该uploads.zip文件存在,之后我已删除该文件夹,但现在推送代码仍出现相同错误,尝试创建新分支也无法解决。
我的.gitignore文件内容如下:
/node_modules /public/hot /public/storage /storage /vendor .env .env.backup .phpunit.result.cache Homestead.json Homestead.yaml npm-debug.log yarn-error.log
解决方案
Git会记录所有历史提交,你删除文件只是在当前版本移除,但历史提交里还保留着这个大文件,所以推送时还是会检测到。按以下步骤处理:
彻底移除历史中的大文件
运行以下命令,替换storage/uploads.zip为你的大文件路径:git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch storage/uploads.zip' --prune-empty --tag-name-filter cat -- --all该命令会遍历所有分支和标签的历史提交,删除指定文件的记录。
清理Git缓存
执行命令清理冗余数据:git gc --prune=now --aggressive强制推送更新后的仓库
因为修改了历史,需要强制推送到远程仓库:git push origin --force --all如果有标签需要同步,再执行:
git push origin --force --tags确认.gitignore生效
检查.gitignore里的/storage规则是否正确,若之前该目录下已有文件被追踪,先移除追踪:git rm -r --cached storage git add . git commit -m "Update .gitignore and untrack storage directory"
内容的提问来源于stack exchange,提问作者user3653474
相关产品推荐
相关产品推荐

