美文网首页Git使用Android开发Android知识
Github如何上传超过100M的大文件

Github如何上传超过100M的大文件

作者: 码农大表哥 | 来源:发表于2018-01-03 17:44 被阅读140次

    笔者我是在github上做了一个开源库(一个灵活配置的自定义相机库(拍照+录制视频))从而录制了一个大概200M+的gif文件,在commit完成了,push的时候 总是报错,大致信息如下:

    remote: Resolving deltas: 100% (472/472), done.
    remote: error: GH001: Large files detected. 
    You may want to try Git Large File Storage - https://git-lfs.github.com.
    

    Total 3007 (delta 664), reused 0 (delta 0)
    remote: error: GH001: Large files detected.
    remote: error: Trace: 7b7de6b9372ee392e0f3961b05ea6f33
    remote: error: See http://git.io/iEPt8g for more information.
    remote: error: File  XXX/XXX/XXX is 234 MB; this exceeds GitHub‘s file size limit of 100.00 MB
    remote: error: File  XXX/XXX/XXX is 234 MB; this exceeds GitHub‘s file size limit of 100.00 MB。
    

    上面错误的原因很好理解就是GitHub不允许直接上传大文件(超过100M)的文件到远程仓库,若要想继续提交可以尝试使用大文件支持库:https://git-lfs.github.com
    LFS使用的简单步骤:

    • 安装git - lfs到本机


      install.png

      我使用的mac,这里有三种安装方式,按自己的习惯来,我用的是Homebrew方式安装。

    1. 安装Git命令行扩展。只需要设置一次Git LFS。
      在项目目录下,执行以下命令:
    git lfs install
    
    1. 选择您希望Git LFS管理的文件类型(或直接编辑.gitattributes)。您可以随时配置其他文件扩展名。这一步成功后会生成一个gitattributes文件
    git lfs track “* .gif” --这里的 “ *.gif "就是你要上传的大文件的路径
    
    1. 添加并commit gitattributes文件
    git add .gitattributes
    
    1. 然后再添加大文件到本地缓存区
    git add demo.gif
    git commit -m "提交项目演示gif图"
    git push 
    

    这里要注意一点:以上是官网步骤,我没这样走。如果你按照以上步骤走的话会还是会出现push fail(如下图)的情况,可参考我的解决办法。

    image.png

    参考解决办法:

    1-2步没变,第3步我是生成.gitattributes后 add并且commit并且把.gitattributes文件push到远程分支,合并完成后,然后再add并且commit然后再push这个大文件.

    简单说,就是我先把这个.gitattributes跟踪文件提交上传到远程,再把大文件提交并上传到远程的,这个要注意顺序。

    有的同学已经把大文件提交了,但是.gitattributes还没有提交,这种情况需要回滚版本,具体操作可以参考廖雪峰 - 版本回退

    相关文章

      网友评论

        本文标题:Github如何上传超过100M的大文件

        本文链接:https://www.haomeiwen.com/subject/jlxknxtx.html