Ubuntu Server 20.04 系统安装(九):ubuntu20.04 安装 Git LFS【通过git命令下载huggingface.io网站中的模型】

GitLFS用于在Git中替换大文件,如音频、视频和图像,通过存储文件内容在远程服务器上。安装包括添加软件源、安装包和配置。使用包括克隆、拉取、推送和跟踪文件模式。gitattributes文件用于指定GitLFS管理的文件类型。
摘要由CSDN通过智能技术生成

前言

因工作需要,要使用Git LFS,主要参考了:Git LFS - large file storage | Atlassian Git Tutorial

一、Git LFS

Git Large File Storage (LFS) 使用 Git 内部的文本指针替换音频样本、视频、数据集和图形等大文件,同时将文件内容存储在 GitHub.com 或 GitHub Enterprise 等远程服务器上。通常用来管理大的二进制文件。
Git LFS 通过将仓库中的大文件替换为微小的指针(pointer) 文件来做到这一点。在正常使用期间,你将永远不会看到这些指针文件,因为它们是由 Git LFS 自动处理的。

关于 LFS 的指针文件:
LFS 的指针文件是一个文本文件,存储在 Git 仓库中,对应大文件的内容存储在 LFS 服务器里,而不是 Git 仓库中,下面为一个图片 LFS 文件的指针文件内容:

version https://git-lfs.github.com/spec/v1
oid sha256:5b62e134d2478ae0bbded57f6be8f048d8d916cb876f0656a8a6d1363716d999
size 285

指针文件很小,小于 1KB。其格式为 key-value 格式,第一行为指针文件规范 URL,第二行为文件的对象 id,也即 LFS 文件的存储对象文件名,可以在.git/lfs/objects 目录中找到该文件的存储对象,第三行为文件的实际大小(单位为字节)。所有 LFS 指针文件都是这种格式。

二、Git LFS的安装

(1)

curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash

在这里插入图片描述

ubuntun默认的软件仓库位置在/etc/apt/sources.list文件中,但在/etc/apt/sources.list.d/目录也有一些软件源(第三方软件的源,可以分别存放不同的第三源地址),我们的git-lfs就是在这个目录下:
在/etc/apt/sources.list.d/目录下多了github_git-lfs.list文件:
在这里插入图片描述


在这里插入图片描述

 (2)

sudo apt-get install git-lfs

在这里插入图片描述

Display the Git LFS environment:

git lfs env

在这里插入图片描述

Error: Failed to call git rev-parse --git-dir: exit status 128

解决上述问题:

git init

执行git init 会生成 /lfs/objects/、/lfs/tmp/目录。
在这里插入图片描述

(3)

Install Git LFS configuration.

git lfs install

在这里插入图片描述
运行 git lfs install 一次,为你的系统初始化后,当你克隆包含 Git LFS 内容的仓库时,Git LFS 将自动进行自我引导启用。

git lfs env

在这里插入图片描述

三、使用Git LFS

(1)
git clone 命令来克隆 Git LFS 仓库,并且将自动为你下载完成检出过程所需的所有 Git LFS 文件:
使用下面两个都可以【git lfs clone会动态显示下载进度】:

git clone
git lfs clone







(2)
git pull 命令拉取 Git LFS 仓库。拉取完成后,所有需要的 Git LFS 文件都会作为自动检出过程的一部分而被下载:

git pull
git lfs pull

(3)
git push提交时:
当向仓库中添加新的大文件类型时,你需要通过使用 git lfs track 命令指定一个模式来告诉 Git LFS 对其进行跟踪:
这是告诉git lfs哪些文件要被git lfs管理,这步非常重要。

$ git lfs track "*.ogg"
Tracking *.ogg
	--View or add Git LFS paths to Git attributes.

比如:
在这里插入图片描述
然后就可以正常的使用git提交lfs文件了:
gitattributes 是一种 Git 机制,用于将特殊行为绑定到某些文件模式。Git LFS 自动创建或更新.gitattributes 文件,以将跟踪的文件模式绑定到 Git LFS 过滤器。但是,你需要将对.gitattributes 文件的任何更改自己提交到仓库:

git lfs track "*.ogg"
git add .  
//git add .gitattributes
git commit -m "log"
git push

(4)
通过调用不带参数的 git lfs track 命令来显示 Git LFS 当前正在跟踪的所有模式的列表(以及它们在其中定义的.gitattributes 文件):

git lfs track

在这里插入图片描述

总结

参考man手册的使用:

git lfs track "*.iso"
git add .gitattributes
git add file.iso
git commit -m "Add disk image"
git push
EXAMPLES
       To get started with Git LFS, the following commands can be used.

       1.  Setup Git LFS on your system. You only have to  do  this  once  per
           repository per machine:

           git lfs install

       2.  Choose  the  type  of files you want to track, for examples all ISO
           images, with git-lfs-track(1):

           git lfs track "*.iso"

       3.  The above stores this information  in  gitattributes(5)  files,  so
           that file need to be added to the repository:

           git add .gitattributes

       4.  Commit, push and work with the files normally:

           git add file.iso
           git commit -m "Add disk image"
           git push

参考资料

Git Large File Storage | 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.

Git LFS - large file storage | Atlassian Git Tutorial
详解 Git 大文件存储(Git LFS) - 知乎
Git Large File Storage | 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.




使用Git LFS使用下载Huggingface的预训练模型到本地 - 知乎

 ubuntu20.04 安装 Git LFS_gitlfs安装_小立爱学习的博客-CSDN博客

下载huggingface上模型的正确姿势_huggingface模型下载_JasonLiu1919的博客-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值