[git] 특정 폴더만 clone이나 fetch 하고 싶을 때

2022. 6. 17. 18:03프로그래밍/형상관리

728x90
728x90

들어가며

일단 결론적으로 clone 명령어로는 특정 폴더를 가져올 수 없는 것으로 보인다.
아무리 찾아봐도 없었다!
git에서는 core.sparseCheckout 옵션을 제공하는데 이것을 이용해서 해결했다.

상황은 프로그램팀 외에 타팀에서 git 저장소의 특정 기능을 이용해야되는데
불필요하게 코드나 파일 접근, 소스 fetch가 필요하지 않기 때문에 일부 폴더만 받을 수 있게 하는 것이다.

해결

예시
계정: elkiss
원격 저장소: localmachine:/usr/local/git/repos/
특정 폴더: Code/SomeFolder/

git init
git remote add -f origin elkiss@localmachine:/usr/local/git/repos/
git config core.sparseCheckout true
echo "Code/SomeFolder/" >> .git/info/sparse-checkout
git pull origin master

git 정보 init
원격 저장소 remote add
부분 체크아웃 config 지정
.git의 sparse checkout 기능에 폴더 지정(윈도우즈에선 해당 폴더에 가면 파일 있음.)
소스업데이트

REF

https://stackoverflow.com/questions/4114887/is-it-possible-to-do-a-sparse-checkout-without-checking-out-the-whole-repository

 

Is it possible to do a sparse checkout without checking out the whole repository first?

I'm working with a repository with a very large number of files that takes hours to checkout. I'm looking into the possibility of whether Git would work well with this kind of repository now that it

stackoverflow.com

Troubleshooting

브랜치 이름에 '|SPARSE'가 계속 나오는 문제... 개발 머신에 이거 자꾸 나오는거 때문에 미칠뻔 했다.
보니깐 최신 버전의 tortoisegit이 sparse-checkout 모듈을 기본적으로 내장하고 있는 듯 하다.
2.35.xx 버전으로 깐 머신에만 저게 나오던 문제라 2.7.xx 구버전으로 롤백했다.
해당 모듈이 config를 세팅하는 순간 |SPARSE를 표시해주는 것으로 보인다.

https://git-scm.com/docs/git-sparse-checkout

 

Git - git-sparse-checkout Documentation

If your repository contains one or more submodules, then submodules are populated based on interactions with the git submodule command. Specifically, git submodule init -- will ensure the submodule at is present, while git submodule deinit [-f] -- will rem

git-scm.com

이게 관련 모듈이고 대충 보니 2020년도에 2.26.xx 버전에 최초로 들어간 모듈인 듯 하다.

728x90
반응형