git push使用LFS上传超过100M的文件,亲测有效

发布时间 2023-10-23 15:21:24作者: 海_纳百川

 

一、问题描述

使用 git push 将一个 173.86 MB 的文件推送到 GitHub 时出现如下报错

remote: error: Trace: 5c39a1831dc9eced8723579b000596bbbeb91a9069931bbdf49b058aaaf1f64c
remote: error: See https://gh.io/lfs for more information.
remote: error: File linux-zero-4.10.y.zip is 173.86 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.
To https://github.com/Gnepuil79/licheepi.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/Gnepuil79/licheepi.git'
 

二、解决方法

根据上述的报错信息,是gitlab服务器段设置的文件大小阈值,其他通过本地设置的方法很难解决问题。

我们看出 push 的资源超过100M,我们可以尝试用 Git 大文件存储 (LFS)

PS:Git 大文件存储(Git Large File Storage (LFS))可以简单的理解为存储大文本、视频、数据集的 Git。以下是官网的定义:

Git 大文件存储(LFS)用 Git 中的文本指针替换音频示例、视频、数据集和图形等大文件,同时将文件内容存储在 GitHub.com 或 GitHub Enterprise 等远程服务器上。

1、下载 Git-LFS,并安装。一般windows下默认安装在c盘program下,下图是安装后的目录

 


2、进入安装后的目录,打开 GitBash,执行 git lfs install
这个命令只需执行这一次即可

 git lfs install

3、以上步骤执行以后关掉git bash页面

4、找到要上传项目,打开项目文件夹,打开 GitBash,我们假设这个项目是完全没有被上传过的,其中A.zip超过100M,以下是上传步骤

git init

git lfs A.zip

git remote add origin 创建的git项目网址

git add .

git commit -m 'init'

git push origin master