Search K
Appearance
Appearance
注意
git lfs install 命令,以启用 Git LFS。.gitattributes 文件中的跟踪规则覆盖 Git LFS 对象。Git LFS 的指针文件看起来像:
version https://git-lfs.github.com/spec/v1
oid sha256:4cac19622fc3ada9c0fdeadb33f88f367b541f38b89102a3f1261ac81fd5bcb5
size 84977953它会跟踪所用 Git LFS 的 version,后接文件的唯一标识符 (oid)。它还会存储最终文件的 size。
Github 仓库 Settings 选项卡 -> Archives 菜单 -> 勾选 Include Git LFS objects in archives (在存档中包含 Git LFS 对象)
> scoop install git-lfs
> git lfs install# Debi
$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
$ sudo apt-get install git-lfs
$ git lfs install
# RHEL
$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
$ sudo yum install git-lfs
$ git lfs install没有特别说明的情况下,Git LFS 不会处理大文件问题,使用 git lfs track 命令进行大文件追踪。
例如追踪一个名为 test.png 的文件,使用 git lfs track "test.png" 命令。
该 .gitattributes 文件已创建,并包含以下信息:
test.jpg filter=lfs diff=lfs merge=lfs -text从现在开始,LFS 将处理此文件。现在,我们可以按照以前的方式将其添加到存储库中。注意,对其他任何更改.gitattributes 也必须提交到存储库:
$ git add .gitattributes
$ git add design-resources/design.psd
$ git commit -m "Add design file"强烈建议将本地 .gitattributes 文件提交到存储库中
.gitattributes 文件,可能会导致在参与其他 Git 项目时发生冲突。.gitattributes 文件允许创建分支或新克隆的人员更轻松地使用 Git LFS 进行协作。.gitattributes 文件允许将 Git LFS 对象选择性地包含在 ZIP 文件和 tarball 存档中。png 的文件,使用 git lfs track "*.png" 命令。png 的文件,也包括以后创建的 png 文件。$ git lfs track$ git lfs ls-files将文件添加到与关联的扩展名相匹配的仓库,提交代码时需要将 .gitattributes 文件也提交到仓库。
git add file.psd
git add .gitattributes提交完成后,执行git lfs ls-files命令可以查看 LFS 跟踪的文件列表。
54dc742407 * file.psd将代码推送到远程仓库后,LFS 跟踪的文件会以“Git LFS”的形式显示:
$ git commit -m "add file.psd"
$ git push origin main
Git LFS: (1 of 1 files) 81.04 MB / 81.04 MB
......使用 git clone 命令
$ git clone git@github.com:ryanjiena/git-lfs-demo.git本地已经存在需要拉取
git lfs fetch origin main使用 git lfs clone 命令
$ git lfs clone git@github.com:ryanjiena/git-lfs-demo.git了解更多 Git LFS 的使用,可执行
git lfs help命令查看帮助。
如需将原有仓库的文件以 LFS 方式存储,查看参考教程。
从 LFS 取消跟踪特定类型的所有文件,并将其从缓存中删除:
$ git lfs untrack "file.psd"
$ git rm --cached "file.psd"将 file.psd 重新添加到常规 git 跟踪中并提交:
$ git add "file.psd"
$ git commit -m "restore "file.psd" to git from lfs"$ git lfs uninstall
Hooks for this repository have been removed.
Global Git LFS configuration has been removed.