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

如何在Git中忽略大文件上传?解决GitHub大文件超限报错

解决Git大文件上传限制及.gitignore无效问题

1. 移除已被Git追踪的大文件

如果目标大文件已经被Git纳入追踪(比如之前提交过),直接添加.gitignore不会生效,得先把它从Git的追踪列表中移除(本地文件会保留):

git rm --cached Pods/MyPath/YandexMapsMobile.xcframework/ios-x86_64_arm64-simulator/YandexMapsMobile.framework/YandexMapsMobile

要是整个Pods目录都不需要追踪,直接执行:

git rm --cached -r Pods

2. 配置.gitignore规则

在项目根目录的.gitignore文件中添加对应忽略规则,示例:

# 忽略整个Pods依赖目录
Pods/
# 或仅忽略该特定大文件
Pods/MyPath/YandexMapsMobile.xcframework/ios-x86_64_arm64-simulator/YandexMapsMobile.framework/YandexMapsMobile

保存文件后提交修改:

git add .gitignore
git commit -m "Update gitignore to exclude large framework files"

3. 清理Git历史中的大文件(若已提交过)

如果大文件已经存在于Git历史记录中,即使移除追踪,推送时仍会触发报错,需要清理历史:
使用git filter-repo工具(比旧的filter-branch更安全高效)执行:

git filter-repo --path Pods/MyPath/YandexMapsMobile.xcframework/ios-x86_64_arm64-simulator/YandexMapsMobile.framework/YandexMapsMobile --invert-paths

清理整个Pods目录的话:

git filter-repo --path Pods/ --invert-paths

清理完成后强制推送到远程仓库:

git push origin --force

⚠️ 强制推送会覆盖远程仓库历史,多人协作项目需提前告知其他成员同步修改后的历史。

4. 替代方案:用Git LFS管理大文件

如果必须追踪该大文件(比如团队共享需求),可以用Git LFS:

  • 安装后在项目初始化:
git lfs install
  • 追踪目标大文件:
git lfs track "Pods/MyPath/YandexMapsMobile.xcframework/ios-x86_64_arm64-simulator/YandexMapsMobile.framework/YandexMapsMobile"
  • 提交自动生成的.gitattributes文件:
git add .gitattributes
git commit -m "Track large framework file with Git LFS"

之后正常推送即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 01:51:03