![cover](https://raw.gitmirror.com/MangoRu/PicGo/master/halo/cover/202405161632046.png)
热知识:Github 仓库上传文件不得大于 100M,解决大文件上传限制
问题描述
今日在 push 一个压缩包至远程 Github 仓库时,发现被拒绝了。这才想起来可能是文件过大导致的,查看详细信息后发现的确如此,通过下面图中可看出:文件大小超出了 100M 限制,也给出了解决方案(git-lfs)。
remote: Resolving deltas: 0% (0/1)
remote: Resolving deltas: 100% (1/1)
remote: Resolving deltas: 100% (1/1), done.
remote: error: Trace: 7f467525f5a6619115d3fa5deb6540ffc64818ab57939fbe091568aef0fe2884
remote: error: See https://gh.io/lfs for more information.
remote: error: File 20240517005046-backup-setNn.zip is 183.10 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
error: failed to push some refs to 'https://github.com/xxx/halo-backup.git'
To https://github.com/xxx/halo-backup.git
! refs/heads/master:refs/heads/master [remote rejected] (pre-receive hook declined)
Done
13:14:18.182: [halo-backup] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false fetch origin --recurse-submodules=no --progress --prune
解决方案
解决方案:Git LFS Git Large File Storage
Git Large File Storage:An open source Git extension for versioning large files
Git LFS 是一个 Git 扩展,用于对大文件进行版本控制的开源 Git 扩展
Git 大文件存储 (LFS) 将音频样本、视频、数据集和图形等大型文件替换为 Git 中的文本指针,同时将文件内容存储在 GitHub.com 或 GitHub Enterprise 等远程服务器上。
1. 下载安装 Git LFS
点击进入官网 Git Large File Storage,下载安装。
注意:git-lfs-windows-v3.5.1.exe 这个版本可能有问题 =》 Could not find Git; can not register Git LFS.
参考 Issues:Could not find Git; can not register Git LFS. · git-lfs/git-lfs · Discussion #5031
下载 Release v3.1.4 · git-lfs/git-lfs 这个版本是可以的。
2. 在 Git 项目中启用 LFS
进入你的 Github 项目的目录地址,打开 Git Bash。
初始化 LFS:
git lfs install
3. 大文件添加入 LFS 的.gitattributes
命令格式:git lfs track 需要上传的大文件路径
git lfs track 20240517005046-backup-setNn.zip
执行后会创建或修改.gitattributes,可通过命令 git lfs track
查看当前加入 lfs 的文件状态。
4. add: 所有待上传的文件加入提交队列中
git add .gitattributes
git add 20240517005046-backup-setNn.zip
5. commit: 提交到远程仓库
git commit -m "commit lfs"
6. push: 推送到远程仓库
git push origin master
查看 Github 远程仓库,OK,上传成功!
- 感谢你赐予我前进的力量