Programing

전체 리포지토리를 먼저 체크 아웃하지 않고 스파 스 체크 아웃을 수행 할 수 있습니까?

lottogame 2020. 6. 8. 07:51
반응형

전체 리포지토리를 먼저 체크 아웃하지 않고 스파 스 체크 아웃을 수행 할 수 있습니까?


체크 아웃하는 데 몇 시간이 걸리는 파일 수가 많은 리포지토리를 사용하고 있습니다. Git이 희소 한 체크 아웃을 지원하므로 Git이 이러한 종류의 저장소와 잘 작동하는지 가능성을 찾고 있지만 찾을 수있는 모든 예제는 다음을 수행합니다.

git clone <path>
git config core.sparsecheckout true
echo <dir> > .git/info/sparse-checkout
git read-tree -m -u HEAD

이 명령 시퀀스의 문제점은 원래 클론도 체크 아웃을 수행한다는 것입니다. 원래 복제 명령에 -n을 추가하면 읽기 트리 명령으로 인해 다음 오류가 발생합니다.

오류 : 스파 스 체크 아웃시 작업 디렉토리에 항목이 남지 않습니다.

모든 파일을 먼저 체크 아웃하지 않고 스파 스 체크 아웃을 수행하려면 어떻게해야합니까?


이 답변은 리포지토리에서 데이터의 전체 복사본을 다운로드합니다. git remote add -f명령은 전체 저장소를 복제합니다. 맨 페이지에서git-remote :

-f옵션을 사용 git fetch <name>하면 원격 정보가 설정된 직후에 실행됩니다.


이 시도:

mkdir myrepo
cd myrepo
git init
git config core.sparseCheckout true
git remote add -f origin git://...
echo "path/within_repo/to/desired_subdir/*" > .git/info/sparse-checkout
git checkout [branchname] # ex: master

이제 path / within_repo / to / desired_subdir (및 해당 경로)에있는 파일 만 사용하여 "정리 된"체크 아웃 된 것을 확인할 수 있습니다.

Windows 명령 행에서 경로를 인용해서는 안됩니다. 즉, 6 번째 명령을 다음과 같이 변경해야합니다.

echo path/within_repo/to/desired_subdir/* > .git/info/sparse-checkout

그렇지 않으면 스파 스 체크 아웃 파일에 따옴표가 나오고 작동하지 않습니다.


Git clone에는 원하는 작업을 수행 하는 옵션 ( --no-checkout또는 -n)이 있습니다.

명령 목록에서 다음을 변경하십시오.

git clone <path>

이에:

git clone --no-checkout <path>

그런 다음 질문에 명시된대로 스파 스 체크 아웃을 사용할 수 있습니다.


태그에 대한 커밋 만 체크 아웃하고 디렉토리를 정리하려는 것을 제외하고는 비슷한 유스 케이스가있었습니다. 를 사용 --depth 1하면 정말 희박 해지고 실제로 속도를 높일 수 있습니다.

mkdir myrepo
cd myrepo
git init
git config core.sparseCheckout true
git remote add origin <url>  # Note: no -f option
echo "path/within_repo/to/subdir/" > .git/info/sparse-checkout
git fetch --depth 1 origin tag <tagname>
git checkout <tagname>

이전에 pavek (감사합니다!)이 게시 한 단일 라이너에서 찾고있는 답변을 찾았으므로 Linux에서 작동하는 단일 회신으로 완전한 답변을 제공하고 싶었습니다 (GIT 1.7.1).

1--> mkdir myrepo
2--> cd myrepo
3--> git init
4--> git config core.sparseCheckout true
5--> echo 'path/to/subdir/' > .git/info/sparse-checkout
6--> git remote add -f origin ssh://...
7--> git pull origin master

나는 명령의 순서를 약간 변경했지만 아무런 영향을 미치지 않는 것 같습니다. 핵심은 5 단계 에서 경로 끝에 슬래시 "/"가 있다는 것입니다 .


슬프게도 위의 어느 것도 나를 위해 일하지 않았으므로 sparse-checkout파일의 다른 조합을 시도하는 데 오랜 시간을 보냈습니다 .

In my case I wanted to skip folders with IntelliJ IDEA configs.

Here is what I did:


Run git clone https://github.com/myaccount/myrepo.git --no-checkout

Run git config core.sparsecheckout true

Created .git\info\sparse-checkout with following content

!.idea/*
!.idea_modules/*
/*

Run 'git checkout --' to get all files.


Critical thing to make it work was to add /* after folder's name.

I have git 1.9


Yes, Possible to download a folder instead of downloading the whole repository. Even any/last commit

Nice way to do this

D:\Lab>git svn clone https://github.com/Qamar4P/LolAdapter.git/trunk/lol-adapter -r HEAD
  1. -r HEAD will only download last revision, ignore all history.

  2. Note trunk and /specific-folder

Copy and change URL before and after /trunk/. I hope this will help someone. Enjoy :)

Updated on 26 Sep 2019


git 2.9 (June 2016) will generalize the --no-checkout option to git worktree add (the command which allows to works with multiple working trees for one repo)

See commit ef2a0ac (29 Mar 2016) by Ray Zhang (OneRaynyDay).
Helped-by: Eric Sunshine (sunshineco), and Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 0d8683c, 13 Apr 2016)

The git worktree man page now includes:

--[no-]checkout:

By default, add checks out <branch>, however, --no-checkout can be used to suppress checkout in order to make customizations, such as configuring sparse-checkout.


Steps to sparse checkout only specific folder:

1) git clone --no-checkout  <project clone url>  
2) cd <project folder>
3) git config core.sparsecheckout true   [You must do this]
4) echo "<path you want to sparce>/*" > .git/info/sparse-checkout
    [You must enter /* at the end of the path such that it will take all contents of that folder]
5) git checkout <branch name> [Ex: master]

Based on this answer by apenwarr and this comment by Miral I came up with the following solution which saved me nearly 94% of disk space when cloning the linux git repository locally while only wanting one Documentation subdirectory:

$ cd linux
$ du -sh .git .
2.1G    .git
894M    .
$ du -sh 
2.9G    .
$ mkdir ../linux-sparse-test
$ cd ../linux-sparse-test
$ git init
Initialized empty Git repository in /…/linux-sparse-test/.git/
$ git config core.sparseCheckout true
$ git remote add origin ../linux
# Parameter "origin master" saves a tiny bit if there are other branches
$ git fetch --depth=1 origin master
remote: Enumerating objects: 65839, done.
remote: Counting objects: 100% (65839/65839), done.
remote: Compressing objects: 100% (61140/61140), done.
remote: Total 65839 (delta 6202), reused 22590 (delta 3703)
Receiving objects: 100% (65839/65839), 173.09 MiB | 10.05 MiB/s, done.
Resolving deltas: 100% (6202/6202), done.
From ../linux
 * branch              master     -> FETCH_HEAD
 * [new branch]        master     -> origin/master
$ echo "Documentation/hid/*" > .git/info/sparse-checkout
$ git checkout master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Already on 'master'
$ ls -l
total 4
drwxr-xr-x 3 abe abe 4096 May  3 14:12 Documentation/
$  du -sh .git .
181M    .git
100K    .
$  du -sh
182M    .

So I got down from 2.9GB to 182MB which is already quiet nice.

I though didn't get this to work with git clone --depth 1 --no-checkout --filter=blob:none file:///…/linux linux-sparse-test (hinted here) as then the missing files were all added as removed files to the index. So if anyone knows the equivalent of git clone --filter=blob:none for git fetch, we can probably save some more megabytes. (Reading the man page of git-rev-list also hints that there is something like --filter=sparse:path=…, but I didn't get that to work either.

(All tried with git 2.20.1 from Debian Buster.)


I'm new to git but it seems that if I do git checkout for each directory then it works. Also, the sparse-checkout file needs to have a trailing slash after every directory as indicated. Someone more experience please confirm that this will work.

Interestingly, if you checkout a directory not in the sparse-checkout file it seems to make no difference. They don't show up in git status and git read-tree -m -u HEAD doesn't cause it to be removed. git reset --hard doesn't cause the directory to be removed either. Anyone more experienced care to comment on what git thinks of directories that are checked out but which are not in the sparse checkout file?

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

반응형