用lfs上传大文件到github


简要

  • 有时候需要将大文件(超过100M)上传到Github上,这时候就需要用到```lfs``,但是其使用有限制的:存储限制大致意思是一个月累计只能上传不超过1GB的文件,带宽一个月累计只能下载不超过1GBGithub说明文档
  • 参考的教程
    • 带有大文件的 GitHub 项目的创建与拉取——使用 Git Large File Storage (LFS)
    • 详解 Git 大文件存储(Git LFS)
    • 官方教程
    • 在使用时创建了一个新账号顺便也记录下Git配置多个github账号

步骤 & 值得留意的步骤

  1. 我首先将除大文件外都上传到 Github 上(此时大文件没有git add,并不在Git本地仓库中)
  2. 确保已经安装了 lfs, 我的大文件叫LeavesDiseaseClassification220327.pth,大小是256M
git lfs install

git lfs track model_data/LeavesDiseaseClassification220327.pth

git add .gitattributes

git add model_data/LeavesDiseaseClassification220327.pth

git commit -m "add Lea.pth"

git push github master 
  • 有注释版本
git lfs install # 执行下没啥坏处

git lfs track "LeavesDiseaseClassification220327.pth" # 一定要加引号 一定要加引号 一定要加引号

git add .gitattributes

git add LeavesDiseaseClassification220327.pth # 这里不需加

git commit -m "add Lea.pth" 

git push github master 
  1. 此时提示完成应该就成功上传了,并且在Github仓库上也可以看到

上传成功但是在仓库没有找到这个文件

上传完成后,在Github->Setting->Billing中的Git LFS Data 中看到有文件了却在仓库找不到(忽略存储未使用)而且commit也没有,很可能是在使用git lfs track追踪文件时没有添加引号,一定要加引号

  • 没有添加引号的错误示例
git lfs track LeavesDiseaseClassification220327.pth # 没有加引号!!!


然后重新添加引号后发现之前的commit也显示出来了

报如图错误


把绿色框中复制粘贴再重新```push````就可以了,