Total Pageviews

Wednesday 20 December 2017

Git的大文件存储 (Git Large File Storage)



在GitHub.com上,上传文件限制为最大100M. 要是上传一个数据库/数据集上去大于100Mb,将会报错, 例如:

    remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.

    remote: error: Trace: b22b3e592b305d6a44ff21d5af86c3a9

    remote: error: See http://git.io/iEPt8g for more information.

    remote: error: File PDBBind/pdbbind_v2014_refined_set.tar.gz is 636.66 MB; this exceeds GitHub’s file size limit of 100.00 MB

    To git@github.com:platinhom/BigDataFile.git

    ! [remote rejected] gh-pages -> gh-pages (pre-receive hook declined)

    error: failed to push some refs to ‘git@github.com:platinhom/BigDataFile.git’


在错误提示里提示你, 大文件需要尝试 Git Large File Storage, 并提供了链接页1. 如果懒得看, 那就直接下载相应版本2 就好了. 提供了多个系统的下载版本任君选择~ 使用前提是要能够使用命令行的Git, window用户可以下载安装基于Mingw的git for windows 3, 装完后用git bash进入命令行即可. 安装git lfs很简单, 下载后直接安装, 解压好后close关闭就好了. 然后在可以运行git的命令行上操作.


Git-LFS是个开源项目, 可以到其Github项目上查看代码 4. Git-LFS对于大文件有更快的克隆和提交的速度, 而操作起来和一般的git并没太大区别.

初始化Git LFS


任何位置运行一次 git lfs init进行初始化和安装git-lfs.


$ git lfs init

Updated pre-push hook.

Git LFS initialized.


初始化成功后就可以用了. 如果没有安装好, 会显示:


$ git lfs init

git: 'lfs' is not a git command. See 'git --help'.


Did you mean this?

        log


注册文件到LFS


例如我要注册tar.gz文件, 可以git lfs track "*.tar.gz". 此时将追踪相应文件后缀名符合的文件. 要是想只是添加某些文件, 指定文件就好了. 追踪成功后会生成一个.gitattributes文件,里面有LFS管理的文件类型信息.


$ git lfs track *.tar.gz

Tracking *.tar.gz


.gitattributes文件写的内容:


*.tar.gz filter=lfs diff=lfs merge=lfs -text

PDBBind/pdbbind_v2014_core_set.tar.gz filter=lfs diff=lfs merge=lfs -text

PDBBind/pdbbind_v2014_refined_set.tar.gz filter=lfs diff=lfs merge=lfs -text


正常提交到github


随后就是一般的提交到github, git add -A; git commit -m "comment"; git push origin master 所有修改都提交也可以.


git add PDBBind/pdbbind_v2014_refined_set.tar.gz

git commit -m "Refine set 2014"

git push origin master


正常情况下, 就能成功提交上去不报错了. 要是报错了, 很有可能是你的大文件之前commit到本地库了, push时还是按之前的方式来提交到github所以报错. 解决办法是撤销上一次commit,或者把库删了重新git clone一次再尝试提交吧(需要再一次git lfs track)…祝好运~

Update


Github的;FS服务要开始要对大容量收费了5..每月1G流量最大1G储存..f**k


    Git LFS is available for both personal and organization accounts. You won’t be charged for minimal large asset support, but plans are available based on your storage and bandwidth usage. Git LFS is available for every repository on GitHub, whether it’s within a free or paid account.

--------------------------------------------------------------

An open source Git extension for versioning large files

Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.

Download v3.4.1 (Windows)

from https://git-lfs.com

No comments:

Post a Comment