Ubuntu 17.04系统git LFS安装及使用

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sinat_20184565/article/details/90413453

 

github不允许存储超过100MB的单个文件,但是提供了git的大文件存储Large File Storage扩展功能。本文假设你已经安装了git。

$ git push -u origin master
Username for 'https://github.com': usernonexist
Password for 'https://usernonexist@github.com': 
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 435.16 MiB | 1.89 MiB/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 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: 592e6ecb32d42ae9324d7165677b3cb1
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File o/openfirewall-1.0.0-base-x86_64.tar.gz is 451.25 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/usernonexist/ofpkgs.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/usernonexist/ofpkgs.git'

 

添加git lfs软件包下载源。

$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
[sudo] password for usernonexist: 
Detected operating system as Ubuntu/zesty.
Checking for curl...
Detected curl...
Checking for gpg...
Detected gpg...
Running apt-get update... done.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/github_git-lfs.list...done.
Importing packagecloud gpg key... done.
Running apt-get update... done.

The repository is setup! You can now install packages.

 

使用标准的ubuntu安装命令安装git-lfs扩展。

$ 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 1004 not upgraded.
Need to get 5,730 kB of archives.
After this operation, 13.9 MB of additional disk space will be used.
Get:1 https://packagecloud.io/github/git-lfs/ubuntu zesty/main amd64 git-lfs amd64 2.7.2 [5,730 kB]
Fetched 5,730 kB in 1min 8s (83.3 kB/s)                                                                                           
Selecting previously unselected package git-lfs.
(Reading database ... 247039 files and directories currently installed.)
Preparing to unpack .../git-lfs_2.7.2_amd64.deb ...
Unpacking git-lfs (2.7.2) ...
Setting up git-lfs (2.7.2) ...
Git LFS initialized.
Processing triggers for man-db (2.7.6.1-2) ...

 

需要撤销在安装LFS之前的那次大文件提交操作,使用git log查看commit标记。

$ git log
commit fe4161c4b8709c9dec4bc7d658284f1b1732f21e
Author: usernonexist <usernonexist@126.com>
Date:   Mon May 20 19:23:15 2019 -0700

    add openfirewall precompiled base system

commit 7028b497bf735eb6a9ccd418944f94d7d921090c
Author: usernonexist <usernonexist@126.com>
Date:   Thu Nov 1 20:26:05 2018 -0700

    update openssh to version 7.9p1
	
...

以下操作撤销提交ID:fe4161c4b8709c9dec4bc7d658284f1b1732f21e。但是命令行需要指定其前一次的commit id:

$ git reset --hard 7028b497bf735eb6a9ccd418944f94d7d921090c
HEAD is now at 7028b49 update openssh to version 7.9p1

 

到git项目的目录,初始化lfs扩展,此初始化仅对当前的代码库生效。

$ git lfs install
Updated git hooks.
Git LFS initialized.

 

指定LFS需要管理的大文件:

$ git lfs track openfirewall-1.0.0-base-x86_64.tar.gz
Tracking "openfirewall-1.0.0-base-x86_64.tar.gz"

 

以下使用标准的git命令提交文件即可。

$ git add openfirewall-1.0.0-base-x86_64.tar.gz*
$ git commit openfirewall-1.0.0-base-x86_64.tar.gz* -m "add base"
[master ab585d4] add base
 2 files changed, 4 insertions(+)
 create mode 100644 o/openfirewall-1.0.0-base-x86_64.tar.gz
 create mode 100644 o/openfirewall-1.0.0-base-x86_64.tar.gz.md5
$ 
$ git push -u origin master
Username for 'https://github.com': usernonexist
Password for 'https://usernonexist@github.com': 
Counting objects: 5, done.% (1/1), 473 MB | 0 B/s                                                                                  
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 558 bytes | 0 bytes/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/usernonexist/ofpkgs.git
   7028b49..ab585d4  master -> master
Branch master set up to track remote branch master from origin.

 

 

展开阅读全文

没有更多推荐了,返回首页