본문 바로가기
C.W.K.
Stream
Lesson 04 of 04 · published

Sparse, partial, shallow, LFS

~22 min · large-repos, sparse-checkout, lfs

Level 0추적 전 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Sparse, partial, shallow, LFS는 서로 다른 크기를 줄여

Linux kernel repo는 5GB, Chromium은 30GB가 넘고 game asset repo는 수백 GB가 될 수 있어. 일반 노트북에서 plain git clone은 고통스럽거나 불가능하지. Git에는 크기를 다루는 mechanism이 넷 있고 각자 줄이는 대상이 달라. 무엇을 포기하고 무엇을 남기는지 알고 골라야 해.

Shallow clone(git clone --depth N)은 최근 N commit만 받아 가장 빠르고 작아. 일회성 CI 실행이나 demo에는 유용하지만 git blame, git bisect와 많은 이력 query가 부정확하거나 불가능해져. 이력이 정말 필요 없을 때만 쓰고 나중에 필요해지면 git fetch --unshallow로 전체 이력을 받아.

Partial clone(git clone --filter=blob:none)은 commit과 tree object를 먼저 받고 blob은 checkout할 때까지 미뤄. Git 2.20+에서 쓸 수 있고, blob 내용이 필요 없는 이력 query는 유지하면서 파일을 실제로 볼 때만 on-demand fetch하므로 많은 작업에서 shallow보다 낫다. --filter=tree:0는 tree도 늦게 받아 매우 좁은 checkout에 유용해.

Sparse checkout은 repo tree에서 어느 path를 작업 directory에 펼칠지 골라. partial clone과 함께 쓰면 거대한 repo에서도 작은 작업 트리를 유지할 수 있어. git sparse-checkout init --conegit sparse-checkout set frontend/ docs/를 실행하면 그 path만 채워. monorepo에서 각 engineer에게 자기 영역에 집중한 workspace를 줄 때 써.

Git LFS는 video, dataset, design asset 같은 큰 binary를 Git repo 안의 작은 pointer file로 바꾸고 본체는 별도 LFS server에 둬. Git diff와 pack은 text에 맞춰져 있어 binary가 많은 프로젝트에는 필수야. git lfs track "*.psd"로 file type을 지정하고 git-lfs hook을 설치하면 push와 pull이 binary를 LFS storage로 자동 전달해.

Code

Shallow vs partial clone·bash
# Shallow — 빠름, history depth 없음:
git clone --depth 1 https://github.com/torvalds/linux.git
# git blame 과 bisect 가 제한됨.

# Partial — modern, lazy blob fetch:
git clone --filter=blob:none https://github.com/torvalds/linux.git
# 파일 실제 열 때 blob 이 on demand fetch.

# Tree-also-deferred (sparse-checkout 과 최고):
git clone --filter=tree:0 https://github.com/...

# Shallow → full history 승격:
git fetch --unshallow
Monorepo 집중을 위한 sparse-checkout·bash
# Clone 된 repo 안에서 cone mode 로 sparse-checkout init:
git sparse-checkout init --cone

# Working tree 에 이 path 만 실체화:
git sparse-checkout set frontend/web docs/api

# 나중에 path 추가:
git sparse-checkout add backend/auth

# Sparse-checkout 비활성화 (full tree):
git sparse-checkout disable

# Partial clone 과 결합 = monorepo 콤보:
git clone --filter=blob:none --sparse https://...
cd repo
git sparse-checkout init --cone
git sparse-checkout set my/team/path
큰 binary asset 용 Git LFS·bash
# 머신에 git-lfs 한 번 설치:
brew install git-lfs        # macOS
git lfs install              # 현재 사용자 hook 등록

# Repo 안에서 LFS storage 용 파일타입 표시:
git lfs track "*.psd"
git lfs track "*.mp4"
git add .gitattributes
git commit -m "Configure LFS for design + video assets"

# 평소처럼 push — git-lfs 가 가로채 binary 를 LFS 서버에 저장.

# 이 repo 의 LFS 콘텐츠 검사:
git lfs ls-files

External links

Exercise

큰 public repo, 예를 들어 https://github.com/torvalds/linux.git--depth 1 shallow와 --filter=blob:none partial 두 방식으로 clone해. 각각 시간을 재고 du -sh로 disk 사용량을 기록해. Partial clone에서는 최근 파일에 git log -p를 실행해 lazy fetch를 관찰하고, 더 작은 repo에서는 sparse checkout으로 subdirectory 하나만 펼쳐. 실제 일에 채택할 mechanism과 이유를 적어봐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.