git lfs: git 中的大文件管理
在 git 中管理大文件
🕐
安装
# 有时候需要升级一下 brew
brew update -v
brew install git-lfs
# check
git lfs install
# 老版系统升级之后,可以安装
Warning: git-lfs 3.5.1 is already installed and up-to-date.
To reinstall 3.5.1, run:
brew reinstall git-lfs与husky冲突
$ git lfs install
Hook already exists: pre-push
#!/usr/bin/env sh
. "${0%/*}/h"
To resolve this, either:
1: run `git lfs update --manual` for instructions on how to merge hooks.
2: run `git lfs update --force` to overwrite your hook.常用命令
git init #创建本地仓库环境
git lfs install #安装大文件上传应用
git lfs track * #追踪要上传的大文件,*表示路径下的所有文件
git add .gitattributes #添加先上传的属性文件(要先上传属性文件,不然有可能失败)
git commit -m "pre" #添加属性文件上传的说明
git remote add origin https://github.com/Youpeng-Zhang/MOP.git #建立本地和Github仓库的链接
git push origin master #上传属性文件
git add * #添加要上传的大文件,*表示路径下的所有文件
git commit -m "Git LFS commit" #添加大文件上传的说明
git push origin master #上传大文件
# 拉取大文件(默认clone就会自动拉取这些文件)
git lfs fetch
# 拉取所有的文件
git lfs ls-files --all
# 不自动摘取lfs文件(测试有效果)
GIT_LFS_SKIP_SMUDGE=1 git clone SERVER-REPOSITORY初始化
$ git lfs install
Updated Git hooks.
Git LFS initialized.添加 track files
git lfs track assets
加入 lfs 失败
修改 .gitmodules 的 track 文件
git lfs track assets/images/*.png

测试是否加入 lfs 成功
git-lfs-notes on 🌱 main via 🐠 v20.13.1
$ git lfs ls-files --all
git-s28b7669c01 * assets/images/large-picture.png
ize
git-lfs-notes on 🌱 main via 🐠 v20.13.1
$ git-size
count: 5
size: 20.00 KiB
in-pack: 12
packs: 1
size-pack: 2.59 KiB
prune-packable: 0
garbage: 0
size-garbage: 0 bytes
🔗 参考链接
- https://github.com/aric-notes/git-lfs-notes
- https://stackoverflow.com/questions/42019529/how-to-clone-pull-a-git-repository-ignoring-lfs
- https://docs.github.com/zh/repositories/working-with-files/managing-large-files/installing-git-large-file-storage
- https://blog.csdn.net/qq_21048115/article/details/130344884
- https://www.bilibili.com/video/BV1GR4y117H4
- https://medium.com/@weiberson/git-lfs介紹-為何需要它-86d9ea3f3ed7