GitHub 大文件上传解决方案

image

背景

想要将本地Git管理的代码提交至GitHub开源

上传错误提示

Writing objects: 100% (542/542), 71.67 MiB | 1.56 MiB/s, done.
Total 542 (delta 256), reused 0 (delta 0)
remote: Resolving deltas: 100% (256/256), completed with 43 local objects.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 774d55b0ae81922e9f86e4c89c232beb
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File Pods/Google-Mobile-Ads-SDK/Frameworks/frameworks/GoogleMobileAds.framework/GoogleMobileAds is 118.00 MB; this exceeds GitHub's file size limit of 100.00 MB

问题分析 & 解决思路

GitHub 不允许上传超过100M的文件

  • 增加.gitignore 文件将Pods/忽略
  • 移除Pods/路径下的所有文件
  • 解决不能上传超过100M文件的限制

解决方案

1. 增加.gitignore 文件将Pods/忽略

新增了.gitignore文件,填入 Pods/,commit本次提交,并将此次commit rebase到大文件添加的前一次commit,完毕后上传,仍然提示错误。具体原因未知,如果哪位大神有知道的,还希望在评论处帮忙解惑,谢谢!至此,放弃此种方案。

2. 移除Pods/路径下的所有文件

移除Pods/路径下的所有文件,并commit,并将此次commit rebase到大文件添加的前一次commit,完毕后上传,也提示错误。此次错误的原因是:需要将所有commit节点含这个大文件的提交都进行一次删除大文件操作,这里是有方案能解决的,可参考这个哥们的方案https://www.cnblogs.com/qmmq/p/4604862.html,具体操作笔者未尝试,因为笔者嫌这种方案麻烦,遂放弃。

3. 解决不能上传超过100M文件的限制

这个方案是根据错误提示解决的
Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.

具体步骤参考:https://git-lfs.github.com

这里以笔者遇到的具体错误进行操作

经过以下两个命令后,说明你已经成功安装git-lfs

brew install git-lfs
git lfs install

track 你的大文件

git lfs track "Pods/Google-Mobile-Ads-SDK/Frameworks/frameworks/GoogleMobileAds.framework/GoogleMobileAds"

Make sure .gitattributes is tracked

git add .gitattributes

这时候你的git仓库下会多出一个文件.gitattributes,里面的内容就是
Pods/Google-Mobile-Ads-SDK/Frameworks/frameworks/GoogleMobileAds.framework/GoogleMobileAds

最后将这次修改commit,然后通过git命令 git rebase -i xxxx将本次提交交换至 xxxx的前一次commit。(xxxx 这里代表的是添加大文件前的那次commit )

恭喜?,上面一系列操作完成后,git push提交吧!

Uploading LFS objects: 100% (1/1), 124 MB | 1.7 MB/s, done
Counting objects: 550, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (532/532), done.
Writing objects: 100% (550/550), 20.23 MiB | 1.56 MiB/s, done.
Total 550 (delta 260), reused 0 (delta 0)
remote: Resolving deltas: 100% (260/260), completed with 43 local objects.

猜你喜欢

转载自blog.csdn.net/Yj_sail/article/details/85274707