基于此答案由apenwarr与此评论被Miral我想出了以下解决方案克隆时救了我近94%的磁盘空间的linux git仓库在本地,而只想要一个文档子目录:
$ 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 .
所以我从2.9GB减少到182MB,这已经很安静了。
我虽然没有将其与git clone --depth 1 --no-checkout --filter=blob:none file:///…/linux linux-sparse-test
(在此处提示)一起使用,但随后丢失的文件全部作为已删除文件添加到索引中。因此,如果有人知道git clone --filter=blob:none
for 的等效项git fetch
,我们可能可以节省更多兆字节。(阅读的手册页git-rev-list
还暗示有类似的东西--filter=sparse:path=…
,但我也没有使它起作用。
(所有尝试使用Debian Buster的git 2.20.1。)