解决git不能超过100M

本文详细介绍了如何解决GitHub上超过100MB文件的上传限制,包括移除错误缓存、重新提交、使用GitLargeFileStorage等步骤,并提供了常见问题的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载自http://www.liuxiao.org/2017/02/git处理-github-不允许上传超过-100mb-文件的问题/

最近在使用 Github 时候遇到一个问题,有一些过大的文件不允许上传,例如:
remote: error: File Examples/iOSDemo/Pods/dependency/libg2o.a is 440.12 MB; this exceeds GitHub's file size limit of 100.00 MB

但有的时候我们还是需要上传这些大文件,这时候怎样做呢?

1、移除错误缓存
首先应该移除所有错误的 cache,对于文件:

Shell
git rm --cached path_of_a_giant_file
1
git rm -- cached path_of_a_giant_file

对于文件夹:

Shell
git rm --cached -r path_of_a_giant_dir
1
git rm -- cached - r path_of_a_giant_dir

例如对于我的例子就是这样的:

Shell
git rm --cached -r Examples/iOSDemo/Pods/dependency/libg2o.a
1
git rm -- cached - r Examples / iOSDemo / Pods / dependency / libg2o .a

2、重新提交:
编辑最后提交信息:

Shell
git commit --amend
1
git commit -- amend

修改 log 信息后保存返回。

重新提交:

Shell
git push
1
git push

3、将大文件加入 Git Large File Storage:
1)首先安装 git-lfs

Shell
brew install git-lfs
1
brew install git - lfs

2)将想要保存的大文件 “路径” 或者 “类型” 添加进 track:

Shell
git lfs track "name_of_a_giant_file"
1
git lfs track "name_of_a_giant_file"

例如对于我的例子就是这样的:

Shell
git lfs track "libg2o.a"
1
git lfs track "libg2o.a"

* 需要注意的是这里面仅能添加类型的扩展名或者文件名作为跟踪方式,不可以添加路径或者目录进行跟踪。

4、将想要保存的大文件正常添加进 git:

Shell
git add path_of_a_giant_file
1
git add path_of_a_giant_file

或者:

Shell
git add extension_name_of_giant_files
1
git add extension_name_of_giant_files

例如对于我的例子就是这样的:

Shell
git add Examples/iOSDemo/Pods/dependency/libg2o.a
1
git add Examples / iOSDemo / Pods / dependency / libg2o .a

5、正常进行提交&推送:

Shell
git commit -m "Add design file" git push origin master
1
2
git commit - m "Add design file"
git push origin master

补充技巧:
提交以后出错再进行上面的步骤可能比较麻烦,如果你已知自己提交的版本库中确实存在一些大于 100MB 的文件,不妨先搜索:

Shell
find ./ -size +100M
1
find . / - size + 100M

然后将这些文件移除,等待其他文件提交完后再复制回来,这样只需要从步骤3的操作开始就可以了。

常见问题:
1、错误:fatal error: unexpected signal during runtime execution
goroutine 23 [chan receive]:
github.com/github/git-lfs/lfs.ScanRefsToChan.func2(0xc8200d4540, 0xc8200c6000, 0xc8200d45a0)
/Users/rick/go/src/github.com/github/git-lfs/lfs/scanner.go:153 +0x4e
created by github.com/github/git-lfs/lfs.ScanRefsToChan
/Users/rick/go/src/github.com/github/git-lfs/lfs/scanner.go:160 +0x30c

出现这个问题通常是由于 go 引擎未安装或者版本太老(1.5.1及以下版本在 Mac 上面有未知错误),或者 git-lfs 版本太老。如果没有安装 go,可使用如下命令安装:

Shell
brew install git-lfs
1
brew install git - lfs

然后使用如下命令升级:

Shell
brew update brew upgrade go brew upgrade git-lfs
1
2
3
brew update
brew upgrade go
brew upgrade git - lfs

然后使用如下命令查看:

Shell
git-lfs version
1
git - lfs version

我这里的版本号如下,如果你比我的版本高就对了,否则可以尝试卸载之前安装的 go 和 git-lfs 重新安装:
git-lfs/1.5.5 (GitHub; darwin amd64; go 1.7.4)

参考文献:
[1] https://help.github.com/enterprise/11.10.340/user/articles/working-with-large-files/
[2] https://git-lfs.github.com/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值