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

GitHub推送遇大文件检测错误,已尝试LFS等方法仍未解决

解决GitHub推送时node_modules大文件历史残留问题

问题核心是你的Git提交历史里已经包含了resources/node_modules/.cache/default-development下的大文件——就算现在删除文件夹、添加.gitignore,GitHub的大文件检测依然会扫描整个历史记录,所以之前的操作没能解决问题。试试下面的步骤:

  • 彻底清理Git历史中的node_modules文件夹
    推荐用git filter-repo(比旧的git filter-branch更安全高效),执行命令:

    git filter-repo --path resources/node_modules --invert-paths
    

    如果没安装git filter-repo,可以通过包管理器安装(比如brew install git-filter-repo或sudo apt-get install git-filter-repo)。
    也可以用BFG Repo-Cleaner,下载jar包后执行:

    java -jar bfg.jar --delete-folders resources/node_modules
    
  • 强制推送到GitHub远程
    因为改写了提交历史,必须强制推送覆盖远程分支:

    git push origin main --force
    

    要是团队协作的话,记得提前告知其他成员,让他们重新拉取分支(本地历史已和远程不一致)。

  • 确认.gitignore配置生效
    检查你的.gitignore文件,确保有resources/node_modules/这一行(路径要和实际目录对应)。如果之前有缓存残留,执行:

    git rm -r --cached resources/node_modules
    git add .gitignore
    git commit -m "Exclude resources/node_modules from Git"
    
  • 后续预防措施

    • 永远不要把node_modules提交到仓库,确保.gitignore里一直保留该路径
    • 依赖包通过npm install或npm ci从package.json安装,不要依赖Git仓库里的node_modules

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 01:56:08