จากคำตอบนี้โดยapenwarrและความคิดเห็นนี้โดยMiralฉันคิดวิธีแก้ปัญหาต่อไปนี้ซึ่งช่วยฉันเกือบ 94% ของพื้นที่ดิสก์เมื่อทำการโคลนพื้นที่เก็บข้อมูล linux git ภายในเครื่องในขณะที่ต้องการไดเรกทอรีย่อย Documentation เดียวเท่านั้น
$ 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
สำหรับgit fetch
เราอาจจะสามารถบันทึกเมกะไบต์เพิ่มเติม (การอ่าน man page ของgit-rev-list
คำใบ้ก็มีบางสิ่งที่เหมือน--filter=sparse:path=…
กัน แต่ฉันก็ไม่ได้ทำงานเช่นกัน
(พยายามทั้งหมดด้วย git 2.20.1 จาก Debian Buster)