使用Git LFS托管大文件

一、安装

#当前操作系统为centos7
[root@localhost ~]#curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
[root@localhost ~]# yum install git-lfs
[root@localhost ~]# git lfs install
[root@localhost ~]# git lfs -v
git-lfs/3.3.0 (GitHub; linux amd64; go 1.19.3; git 77deabdf) 

二、代码库启用LFS

[root@localhost ~]# cd /mnt/
[root@localhost mnt]# git clone git@codeup.aliyun.com:pc-xvista.git
[root@localhost mnt]# cd pc-xvista
[root@localhost pc-xvista]# git lfs track "*.mp4"  #将MP4文件使用LFS管理,此处的指令并不会对已存在的MP4文件进行管理,如果需要管理已存在的MP4文件请参考下放使用参考链接中的2.2章节
Tracking "*.mp4" 
[root@localhost pc-xvista]# git lfs track  #查看当前 track规则
    *.mp4 (.gitattributes)
Listing excluded patterns
[root@localhost pc-xvista]# cd www.xvista.com/html/images
[root@localhost images]#  git lfs track "*.mp4"  #track规则可以有多个,并且可以更加具体路径添加
Listing tracked patterns
    www.xvista.com/html/images/*.mp4 (www.xvista.com/html/images/.gitattributes)
    *.mp4 (.gitattributes)
Listing excluded patterns
[root@localhost images]# git add .gitattributes  #一定要把 .gitattributes文件提交并上传,并且如果有多个需要都提交,当前提交的为 image下,而不是项目下,按需
[root@localhost images]# git commit -m "Add \"*.MP4\" LFS config "

三、上传mp4文件

[root@localhost images]# git add video_new.mp4
[root@localhost images]# git add video_new.mp4
[root@localhost images]# git commit -m "LFS manager MP4"
[root@localhost images]# git push 
Uploading LFS objects: 100% (1/1), 95 MB | 4.3 MB/s, done.   #可以看到upload LFS done字样
.....

四、仓库验证  

可以看到video_new.mp4已经被标记使用LFS管理了

重新clone代码查看(略)

五、注意事项

使用LFS管理后,拉取机器上也必须安装git-lfs,否则只能拉取拉取后文件内容为 Git LFS Pointer 文件内容(version,oid和size),而无法将真正存储在 Git LFS 的文件拉取到本地。

 

安装参考地址:https://help.aliyun.com/document_detail/206889.htm?spm=a2c4g.11186623.0.0.42067c55lrZ2kd#topic-2042160

使用参考地址:https://help.aliyun.com/document_detail/321367.html

posted @ 2022-12-12 10:35  百衲本  阅读(458)  评论(0编辑  收藏  举报
cnblogs_post_body { color: black; font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif; font-size: 15px; } cnblogs_post_body h1 { text-align:center; background: #333366; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 23px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h2 { text-align:center; background: #006699; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 20px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h3 { background: #2B6695; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 18px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } 回到顶部 博客侧边栏 回到顶部 页首代码 回到顶部 页脚代码