Git Large File Storage
An open source Git extension for versioning large files
Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.
Git_Large_File_Storage_-_graphic.gif
How to install
- Homebrew:
brew install git-lfs
- MacPorts:
port install git-lfs
DEB
$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
$ sudo apt-get install git-lfs
Ubuntu
Getting Started
Download and install the Git command line extension. You only have to set up Git LFS once.
Select the file types you'd like Git LFS to manage (or directly edit your .gitattributes). You can configure additional file extensions at anytime.
There is no step three. Just commit and push to GitHub as you normally would.
LFS Pull
외부 저장소에서 데이터를 받을 경우 아래와 같이 입력하면 된다.
LFS 해제하기
LFS 파일 목록
$ git lfs ls-files --all
2383379170 * recc_daemon_vision/seven_segment/ckps/faster_rcnn_r50_fpn_1x_coco_211006/seven_segment_20211007.pth
70eacdbba1 * recc_daemon_vision/seven_segment/ckps/faster_rcnn_r50_fpn_1x_coco_211006/seven_segment_20211028_adam.pth
c51b851e57 * recc_daemon_vision_tester/samples/ssd_sample_01.jpg
LFS로 관리되는 파일 목록 확인
모든 커밋에서 git lfs 추적 해제
모든 파일들의 git lfs 추적 해제
.ext
확장자를 가진 파일들의 git lfs 추적 해제
WARNING |
좀 오래 걸린다 |
Removing objects from LFS
- Git Large File Storage (LFS) | GitLab
- (git lfs untrack) 깃, lfs 추적 해제, 원격 저장소 lfs 저장공간 확보 | syki66 blog
- https://stackoverflow.com/questions/35011366/move-git-lfs-tracked-files-under-regular-git
- https://stackoverflow.com/questions/59551850/remove-git-lfs-with-filter-branch-cant-re-add-unchanged-file-to-index
- https://docs.github.com/en/github/managing-large-files/removing-files-from-git-large-file-storage#git-lfs-objects-in-your-repository
LFS에서 객체를 제거하려면:
-
git filter-repo
를 사용하여 저장소에서 객체를 제거합니다. -
.gitattributes
파일에서 제거한 개체에 대한 관련 LFS 줄을 삭제하고 해당 변경 사항을 커밋합니다. -
git lfs uninstall
- lfs hook 제거
커밋 히스토리에서 .gitattributes 파일 제거
git filter-branch -f --prune-empty --tree-filter 'git rm -f .gitattributes --ignore-unmatch' --tag-name-filter cat -- --all
Staging 상태 확인
$ $ git lfs status
On branch master
Git LFS objects to be pushed to origin/master:
Git LFS objects to be committed:
cvtoolkit/apps/kra/__init__.py (Git: e3b0c44)
cvtoolkit/apps/kra/kra.py (Git: a9a96b0)
cvtoolkit/arguments.py (Git: 3bf1b06 -> Git: b67e097)
cvtoolkit/assets/__init__.py (Git: dd1bf6e -> Git: 573d2e3)
cvtoolkit/assets/videos/kra/20230428-front1.mp4 (LFS: 52a6923)
cvtoolkit/assets/videos/kra/20230428-front2.mp4 (LFS: ac3d2fe)
cvtoolkit/assets/videos/kra/20230428-front3.mp4 (LFS: 384df63)
cvtoolkit/assets/videos/kra/20230428-front4.mp4 (LFS: ad05f4a)
cvtoolkit/entrypoint.py (Git: beab68d -> Git: 243c233)
Git LFS objects not staged for commit:
저장공간 확보
.gitattribute 의 -text
의 의미
- git lfs - Should I always exclude text attribute for git LFS files? - Stack Overflow
- Git - gitattributes Documentation
-text
는 text 속성을 해제한다는 뜻이다.
# Treat *.otf as **not** text
*.otf filter=lfs diff=lfs merge=lfs -text
# Treat *.otf as text
*.otf filter=lfs diff=lfs merge=lfs text
-text
를 생략하면 .gitattributes 파일에서 설정한 기본값이 사용됩니다. 따라서 -text
를 남겨 두는 것이 좋습니다.
Troubleshooting
git-lfs-authenticate (Errno::ENOENT)
아래와 같이 버그가 발생될 수 있다.
$ git lfs pull
Git LFS: (0 of 8 files) 0 B / 855.26 MB
batch request: exit status 1: /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_shell.rb:143:in `exec': No such file or directory - git-lfs-authenticate (Errno::ENOENT)
from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_shell.rb:143:in `exec_cmd'
from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_shell.rb:117:in `process_cmd'
from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_shell.rb:35:in `exec'
from /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell:24:in `<main>'
이 경우 LFS의 URL이 없어서 발생되는 문제일 수 있다. 아래와 같이 URL을 추가하면 된다.
참고로 GitLab의 경우 http://host/user/repo.git/info/lfs
와 같이 URL을 적어주면 된다.
결과적으로 아래와 같은 형식으로 .git/config
파일에 정보가 기입된다.
[lfs]
url = "http://server/proj/americano.git/info/lfs"
[lfs "http://server/proj/americano.git/info/lfs"]
access = basic
See also
- Git
- git-annex
- lfs-folderstore - Git LFS: Shared Folder agent
- DVC (Data Version Control)