2023-3-28
git默认不支持大文件的管理,通过LFS的安装,可以很方便的管理大文件资料。
本文简单记录LFS的使用
官网:https://git-lfs.com/
在git仓库根目录,新建文件.gitattributes
文件;
设置指定类型的文件,被LFS管理。
*.exe filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.msi filter=lfs diff=lfs merge=lfs -text
以上两步,基本就够用了。
git lfs version
如果遇到版本不生效,可以试着把git-lfs.exe移动到git目录下
git-lfs
binary on your system’s executable $PATH
or equivalent.$ git lfs install
To begin using Git LFS within a Git repository that is not already configured
for Git LFS, you can indicate which files you would like Git LFS to manage.
This can be done by running the following from within a Git repository:
$ git lfs track "*.psd"
(Where *.psd
is the pattern of filenames that you wish to track. You can read
more about this pattern syntax
here).
Note: the quotation marks surrounding the pattern are important to
prevent the glob pattern from being expanded by the shell.
After any invocation of git-lfs-track(1)
or git-lfs-untrack(1)
, you must
commit changes to your .gitattributes
file. This can be done by running:
$ git add .gitattributes
$ git commit -m "track *.psd files using Git LFS"
You can now interact with your Git repository as usual, and Git LFS will take
care of managing your large files. For example, changing a file named my.psd
(tracked above via *.psd
):
$ git add my.psd
$ git commit -m "add psd"
Tip: if you have large files already in your repository’s history,
git lfs track
will not track them retroactively. To migrate existing large files
in your history to use Git LFS, usegit lfs migrate
. For example:$ git lfs migrate import --include="*.psd" --everything
You can confirm that Git LFS is managing your PSD file:
$ git lfs ls-files
3c2f7aedfb * my.psd
Once you’ve made your commits, push your files to the Git remote:
$ git push origin master
Uploading LFS objects: 100% (1/1), 810 B, 1.2 KB/s
# ...
To https://github.com/git-lfs/git-lfs-test
67fcf6a..47b2002 master -> master