GitHub上传超过100M的单个文件(包括处理和解决)

版权声明:本文为博主原创文章,版权均归本人所有,任何人或团体、机构全部转载或者部分转载、摘录,请保留本博客链接或标注来源。博客地址:https://blog.csdn.net/qq_31285709/article/details/105026835

一、背景

在完善毕设的过程中,有使用STK生成的卫星轨道数据,1000多颗卫星两个小时(7200秒)的数据保存在csv文件中。这一个文件包含7203×1000行数据,一共315.7M。毕设的系统实时更新上GitHub,但是在同步这个文件时遇到了问题。

二、问题详情

在某一次系统代码和文件修改中,我修改了一个常规文件,然后加入了这个315M的csv文件,于是想把这两个改动同步到GitHub上。
按照正常流程进行git add、git commit、git push这两个改动的地方。
在git push运行输入账号密码之后显示:

root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git push https://github.com/我的账号/我的项目.git
Username for 'https://github.com': 我的账号
Password for 'https://我的账号@github.com':
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 141.21 MiB | 5.41 MiB/s, done.
Total 8 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 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: a54c2204be132cb46c9fb4fe3817a14f
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File 我的的项目/settings/locationflie/edge_devices/mist Fixed Position.csv is 315.70 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/我的账号/我的项目.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/我的账号/我的项目.git'

显示主要的问题是我的文件太大了,GitHub检测到我push的commit里面包含一个大于100M的文件。
remote: error: GH001: Large files detected.
remote: error: File mist Fixed Position.csv is 315.70 MB; this exceeds GitHub’s file size limit of 100.00 MB

三、问题处理

此时是在push上去的过程中出现的问题。如果这是最近一次commit,并且还没有push到github上,为了保证在这次commit没有问题的文件还能够顺利的push上去,需要把在这次push的过程中出现问题的文件移除本次commit。
在这里我需要把mist Fixed Position.csv这个文件移除这次的commit中,然后把没有问题的文件push上去。

1.首先是移除的操作

在你之前git add的路径下(需要移除的文件的路径下)运行:

git rm --cached "需要移除的文件名.后缀"

移除成功会有显示,说明文件已经移除当前commit,如下:

rm '我的项目/settings/locationflie/edge_devices/mist Fixed Position.csv'

如果移除不成功可能会显示没有这个文件,可能是你当前的文件路径不对。一定要到要移除的文件的本地路径下运行git rm命令。
提示:该命令不会把本地文件删除。

2.重新commit

把没有问题的文件按照之前的commit再重新commit。

git commit --amend -CHEAD

如果成功会有一个commit编号,显示成功添加commit,如下:

[master b54c3e6] update 2020.3.22 1.40
 Date: Sun Mar 22 01:40:32 2020 +0800
 1 file changed, 1 insertion(+)
 create mode 100644 我的项目/settings/locationflie/edge_devices/改动的文件

3.把重新commit好的文件push上去

git push https://github.com/我的账号/我的项目.git

输入账户名和密码之后就可以成功把没有问题的文件按照之前的commit给push上去了,最后会显示添加完成。

4.问题处理全部过程

下面给出问题处理的全部过程,基本上除了一开始git rm那里可能会遇到问题其他地方还没有问题。

root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git rm --cached "mist Fixed Position.csv"
rm '我的项目/settings/locationflie/edge_devices/mist Fixed Position.csv'
root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git commit --amend -CHEAD
[master b54c3e6] update 2020.3.22 1.40
 Date: Sun Mar 22 01:40:32 2020 +0800
 1 file changed, 1 insertion(+)
 create mode 100644 我的项目/settings/locationflie/edge_devices/改动的文件
root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git push https://github.com/我的账号/我的项目.git
Username for 'https://github.com': 我的账号
Password for 'https://我的账号@github.com':
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 576 bytes | 115.00 KiB/s, done.
Total 7 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To https://github.com/我的账号/我的项目.git
   c162e69..b54c3e6  master -> master

四、问题解决

1.解决思路

在处理完git push遇到的问题之后,现在需要考虑如何把mist Fixed Position.csv(315.7M)这个超过100M的文件push到GitHub上。
在网上查了一下解决方法,大概有两种。

a. 第一种是git config修改(有待考究)
在终端运行:git config http.postBuffer 524288000
然后通过git config -l 可以查看配置的内容。
配置内容会多出一条:http.postbuffer=524288000
这说明git设置 http.post缓存设置为500M,可以理解为push的全部文件大小加起来可以有500M。(对于http.postBuffer这个配置我没有证实过实现的效果,我也不知道理解是否正常,有待了解
但是之后我把mist Fixed Position.csv通过git add、git commit、git push之后,还是会显示文件太大,不能超过100M的提示。
这个方法似乎没有达到想要的效果,因为单文件大于100M的问题没有解决。

b.第二种是git lfs的方法(推荐使用)
很多博主都有提到这个方法,而且有效。但是大部分都会提到去官网下载一个 Git LFS 客户端,要不就是安装Homebrew。在这里我只想用Linux命令行安装,不想去装其他的。
于是接下来的解决流程我是用win10的Linux命令行进行操作。

2. 解决流程

解决流程基于git lfs的方法,环境是win10的Linux系统环境。
a.安装git lfs
sudo apt-get install git-lfs
git lfs install

下面是结果显示。

root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# sudo apt-get install git-lfs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  git-lfs
0 upgraded, 1 newly installed, 0 to remove and 294 not upgraded.
Need to get 2129 kB of archives.
After this operation, 7662 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 git-lfs amd64 2.3.4-1 [2129 kB]
Fetched 1092 kB in 14s (80.8 kB/s)
Selecting previously unselected package git-lfs.
(Reading database ... 52251 files and directories currently installed.)
Preparing to unpack .../git-lfs_2.3.4-1_amd64.deb ...
Unpacking git-lfs (2.3.4-1) ...
Setting up git-lfs (2.3.4-1) ...
Processing triggers for man-db (2.8.3-2) ...
root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git lfs install
Updated git hooks.
Git LFS initialized.

b.把大文件添加到 lfs
首先,保证运行命令的文件路径为你想要传的大文件路径下。
git lfs track "需要上传的文件名.后缀"

下面是结果显示。

root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git lfs track "mist Fixed Position.csv"
Tracking "mist Fixed Position.csv"

此时本地文件路径下会生成一个.gitattributes文件。

c. 将.gitattributes文件push
很多博客也提到要先把.gitattributes文件push了之后,再去push超过100Mdde 大文件。
git add .gitattributes
可以通过git status查看git的状态。
git commit -m "此处可编辑说明信息"
git push https://github.com/你的账号/你的项目.git
此时完成了对.gitattributes文件的push。

下面是结果显示。

root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git add .gitattributes
root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   .gitattributes

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        ../../../../.classpath
        ../../../../.project
        ../../../../.settings/
        
root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git commit -m "update 2020.3.22 2.23"
[master ee71609] update 2020.3.22 2.23
 1 file changed, 1 insertion(+)
 create mode 100644 我的项目/settings/locationflie/edge_devices/.gitattributes
root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git push https://github.com/我的账号/我的项目.git
Username for 'https://github.com': 我的账号
Password for 'https://我的账号@github.com':
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 590 bytes | 147.00 KiB/s, done.
Total 7 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To https://github.com/我的账号/我的项目.git
   b54c3e6..ee71609  master -> master

d.将100M以上大文件push
接下来大于100M的文件就可以正常的进行上传操作了。
git add "需要上传的文件名.后缀"
如果之前忽略不把它包含在git版本控制对象里,会有提示是否添加进去。因为之前在git status的时候发现需要上传的文件没有包含在git版本控制对象里。此时需要加上-f操作。
git add "需要上传的文件名.后缀 -f"
git commit -m "此处可编辑说明信息"
git push https://github.com/你的账号/你的项目.git
然后就可以等待你的大文件上传上去了。上传完毕之后就完成把超过100M的大文件push到GitHub上的操作。

下面是结果显示。

root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git add "mist Fixed Position.csv"
The following paths are ignored by one of your .gitignore files:
我的项目/settings/locationflie/edge_devices/mist Fixed Position.csv
Use -f if you really want to add them.
root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git add "mist Fixed Position.csv" -f
root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git commit -m "update 2020.3.22 2.25"
[master fc876d9] update 2020.3.22 2.25
 1 file changed, 3 insertions(+)
 create mode 100644 我的项目/settings/locationflie/edge_devices/mist Fixed Position.csv
root@V:/mnt/d/Others/eclipse/Workspace/我的本地项目路径/settings/locationflie/edge_devices# git push https://github.com/我的账号/我的项目.git
Username for 'https://github.com': 我的账号
Password for 'https://我的账号@github.com':
Git LFS: (1 of 1 files) 315.70 MB / 315.70 MB
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 682 bytes | 227.00 KiB/s, done.
Total 7 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To https://github.com/我的账号/我的项目.git
   ee71609..fc876d9  master -> master

五、参考链接

https://www.cnblogs.com/qmmq/p/4604862.html
https://www.jianshu.com/p/e48d53571bf0
https://blog.csdn.net/wifi74262580/article/details/85060187
https://blog.csdn.net/weixin_39278265/article/details/100541749
https://blog.csdn.net/jjjjjj123321/article/details/84890893

git config http.postBuffer 524288000:https://blog.csdn.net/u010545480/article/details/52995794

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值