Closed2

git sparse-checkout

輝

練習

コマンド

最低限の clone

git clone --filter=blob:none --no-checkout git@github.com:derrickstolee/sparse-checkout-example.git

(base) potatodeiMac:sparse-checkout-example potato$ ls -ltr
total 0

何も fetch していない

sparse checkout set

(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout set client
(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout list
client
(base) potatodeiMac:sparse-checkout-example potato$ ls -ltr
total 0
(base) potatodeiMac:sparse-checkout-example potato$ git branch
* main

client のみが checkout 対象となっている。まだ何も fetch していない。
branch がすでに main になっている

checkout main

(base) potatodeiMac:sparse-checkout-example potato$ git checkout main
remote: Enumerating objects: 189, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 189 (delta 1), reused 3 (delta 1), pack-reused 182
接收对象中: 100% (189/189), 45.98 MiB | 10.18 MiB/s, 完成.
处理 delta 中: 100% (60/60), 完成.
正在更新文件: 100% (197/197), 完成.
已经位于 'main'
您的分支与上游分支 'origin/main' 一致。
(base) potato:sparse-checkout-example potato$ ls -ltr
total 24
-rw-r--r--  1 potato  staff  1162 Oct  9 12:29 LICENSE.md
-rw-r--r--  1 potato  staff  1200 Oct  9 12:29 README.md
-rw-r--r--  1 potato  staff   456 Oct  9 12:29 bootstrap.sh
drwxr-xr-x  6 potato  staff   192 Oct  9 12:29 client

指定したclient と root ディレクトリの下のファイルが fetch された

sparse-checkout add

(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout list
client
(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout add web
remote: Enumerating objects: 1270, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1270 (delta 0), reused 1 (delta 0), pack-reused 1269
接收对象中: 100% (1270/1270), 124.30 MiB | 10.97 MiB/s, 完成.
处理 delta 中: 100% (74/74), 完成.
正在更新文件: 100% (1272/1272), 完成.
(base) potatodeiMac:sparse-checkout-example potato$ ls -ltr
total 24
-rw-r--r--  1 potato  staff  1162 Oct  9 12:29 LICENSE.md
-rw-r--r--  1 potato  staff  1200 Oct  9 12:29 README.md
-rw-r--r--  1 potato  staff   456 Oct  9 12:29 bootstrap.sh
drwxr-xr-x  6 potato  staff   192 Oct  9 12:29 client
drwxr-xr-x  6 potato  staff   192 Oct  9 12:34 web
(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout list
client
web

web がリストに追加されて、同時にweb フォルダのデータも fetch された

sparse checkout set をもう1回をやると

(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout set service
remote: Enumerating objects: 58, done.
remote: Counting objects: 100% (4/4), done.
remote: Total 58 (delta 2), reused 3 (delta 2), pack-reused 54
接收对象中: 100% (58/58), 539.88 KiB | 745.00 KiB/s, 完成.
处理 delta 中: 100% (16/16), 完成.
正在更新文件: 100% (1557/1557), 完成.
(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout list
service

対象リストが上書きされて(service のみになる)、同時に service フォルダのデータが fetch される

sparse checkout disable

  • Repopulate the working directory with all files, disabling sparse checkouts.

(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout disable
remote: Enumerating objects: 1456, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 1456 (delta 0), reused 2 (delta 0), pack-reused 1453
Receiving objects: 100% (1456/1456), 170.27 MiB | 10.22 MiB/s, done.
Resolving deltas: 100% (136/136), done.
Updating files: 100% (1466/1466), done.
(base) potatodeiMac:sparse-checkout-example potato$ ls -ltr
total 24
-rw-r--r--  1 potato  staff  1162 Oct  9 12:52 LICENSE.md
-rw-r--r--  1 potato  staff  1200 Oct  9 12:52 README.md
-rw-r--r--  1 potato  staff   456 Oct  9 12:52 bootstrap.sh
drwxr-xr-x  7 potato  staff   224 Oct  9 12:52 service
drwxr-xr-x  6 potato  staff   192 Oct  9 12:52 client
drwxr-xr-x  6 potato  staff   192 Oct  9 12:52 web
(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout list
fatal: this worktree is not sparse

リポジトリのすべてのデータが fetch された。sparse checkout が無効にされた

sparse checkout set をもう1回をやると

(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout list
fatal: this worktree is not sparse
(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout set service
(base) potatodeiMac:sparse-checkout-example potato$ ls -ltr
total 24
-rw-r--r--  1 potato  staff  1162 Oct  9 12:52 LICENSE.md
-rw-r--r--  1 potato  staff  1200 Oct  9 12:52 README.md
-rw-r--r--  1 potato  staff   456 Oct  9 12:52 bootstrap.sh
drwxr-xr-x  7 potato  staff   224 Oct  9 12:52 service
(base) potatodeiMac:sparse-checkout-example potato$ git sparse-checkout list
service

sparse checkout が有効になって、指定されたディレクトリのみが fetch された

このスクラップは2023/10/09にクローズされました