持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第1天,点击查看活动详情
Git Large File Storage (LFS)
Git Large File Storage (LFS)
Git 大文件存储 (LFS) 使用 Git 内部的文本指针替换音频样本、视频、数据集和图形等大文件,同时将文件内容存储在 GitHub.com 或 GitHub Enterprise 等远程服务器上
安装
Mac上推荐使用 Homebrew 安装
brew install git-lfs
其他平台或安装方式可以参照 git-lfs.github.com/
配置
Step1:初始化 lfs
$ git lfs install
这个命令是全局的 会在当前用户的 .gitconfig 中添加 lfs 相关的如下设置:
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
使用 git lfs uninstall 可以取消这些配置
Step2:配置追踪文件
进入到当前项目仓库,使用 track 命令指定想要追踪的大文件,例如:
# 文件后缀
$ git lfs track "*.gif"
# 具体到某个文件
$ git lfs track "2.gif"
执行 track 之后会在当前 git 仓库下生成 .gitattributes 文件(如果之前没有的话)
// .gitattributes 的内容
*.gif filter=lfs diff=lfs merge=lfs -text
相关命令
- git lfs ls-files 查看当前有哪些文件被 track 了
- git lfs untrack 可以停止追踪文件
Step3:保存&提交
$ git add .gitattributes
$ git commit -m "add .gitattributes"
之后执行 push 操作 可以看到使用 lfs 功能了
$ git push
Uploading LFS objects: 100% (2/2), 187 MB | 0 B/s, done.
Enumerating objects: 28, done.
Counting objects: 100% (28/28), done.
Delta compression using up to 16 threads
Compressing objects: 100% (22/22), done.
Writing objects: 100% (24/24), 1.93 MiB | 1.09 MiB/s, done.
Total 24 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), completed with 2 local objects.
在 git 上也可以看到 lfs 的标识
Tips
错误 Git lfs - "this exceeds GitHub's file size limit of 100.00 MB"
按照上面的3步之后还是失败的原因,可能是之前有 commit,把文件提交过了
可以使用 git lfs migrate 命令把相关文件重新迁移,例如:
$ git lfs migrate import --include="*.gif"
限制
虽然看上去是比较美好的,但是也有许多限制,首先空间当然不可能无限给你用,除非你加钱。。
可以在 github.com/settings/bi… 里面看到自己LFS服务使用的情况
其他的细节可以在 官方wiki里找到 github.com/git-lfs/git…
This page lists common issues and feature requests:
- GitHub currently enforces a 2 GiB size limit per-object.
- Windows clients with Git <2.34 corrupt files > 4Gb (#2434)
- Windows client must have Git Credential Manager installed/and in-use or operations may hang indefinitely (#1763)
- GitLab currently (as of 11.7.3 CE) has a hard coded timeout for the git-lfs-authenticate token of 30 minutes. GitLab also lacks support for the expires_in or expires_at properties which would mitigate this issue. See closed issue: (#3012) comment. Update: a fix was introduced in 11.9 to include the expires_in property. See (#57353) for details.