问题描述
在我们的某个仓库中,存在大量 PDF 文件,我们会频繁操作这些文件。
在提交时,Git 会进行系列操作(比如创建对应的 BLOG 文件),都会消耗很多系统资源。
在笔记将记录:在 Git 中,如何管理大文件,以及常见问题解决方案。
解决方案
GitHub 开发 Git LFS 插件来管理大文件,所以我们使用 git-lfs 来管理这些大文件。
安装插件
# Ubuntu 21.04 TLS apt-get install git-lfs
参考 Installation · git-lfs/git-lfs Wiki 文档,获取其他系统的安装方法。
简单示例
#1 You only need to run this once per user account. git lfs install #2 git lfs track "*.psd" git add .gitattributes #3 git add file.psd git commit -m "Add design file" git push origin main
常见问题处理
GitLab: LFS objects are missing. Ensure LFS is properly set up or try a manual “git lfs push –all”.
问题描述:
# git push origin main Enumerating objects: 1035, done.35), 880 MB | 0 B/s Counting objects: 100% (1035/1035), done. Delta compression using up to 4 threads Compressing objects: 100% (1021/1021), done. Writing objects: 100% (1035/1035), 229.44 MiB | 5.47 MiB/s, done. Total 1035 (delta 276), reused 0 (delta 0) remote: Resolving deltas: 100% (276/276), done. remote: GitLab: LFS objects are missing. Ensure LFS is properly set up or try a manual "git lfs push --all". To http://vcs.example.com/team/tlm.git ! [remote rejected] main -> main (pre-receive hook declined) error: failed to push some refs to 'http://vcs.example.com/team/tlm.git'
解决方案:
# git lfs push --all origin main Uploading LFS objects: 100% (182/182), 9.3 GB | 8.0 MB/s, done. # git push origin main ...
参考文献
Git Large File Storage | Git Large File Storage (LFS)