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

Electron项目GitHub推送因大文件失败,Git LFS使用仍报错求助

解决Electron项目Git推送因大文件被GitHub拒绝的问题

嘿,我一眼就瞅出问题所在了——你只给小文件electron.d.ts加了LFS追踪,但真正触发报错的110MB大文件是node_modules/electron/dist/electron,这个核心大文件根本没被Git LFS接管,所以GitHub还是会拦着你的推送!

另外提个重要的小建议:node_modules文件夹本来就不该提交到Git仓库里,依赖完全可以通过package.json重新安装,提交它只会让仓库臃肿不堪,还容易引发各种版本兼容问题。

下面是一步步的解决步骤:

  1. 先撤销你之前的提交(因为大文件已经被放进提交历史里了,必须先清除掉):
git reset --soft HEAD~1
  1. 把node_modules加入.gitignore,彻底杜绝以后再提交依赖文件夹:
echo "node_modules/" >> .gitignore
  1. 给真正的大文件添加Git LFS追踪:
git lfs track "node_modules/electron/dist/electron"

你可以打开.gitattributes文件检查一下,里面应该会出现类似这样的记录:

node_modules/electron/dist/electron filter=lfs diff=lfs merge=lfs -text
  1. 重新提交文件:
git add .gitignore .gitattributes
git add .
git commit -m "Initial commit: Set up LFS and ignore node_modules"
  1. 最后推送代码到GitHub:
git push origin master

这样操作之后,那个110MB的electron文件就会通过Git LFS上传,GitHub就不会再拒绝你的推送了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 21:02:53