git sparse-checkout

git

書き方

git sparse-checkout set <dir>...

git 2.25で入った命令で、大きなリポジトリのうち指定したフォルダーだけをディスクに置きます。履歴は丸ごとあり、coneモードはグロブではなくフォルダー名を取ります。

よく使うオプション

オプション意味
set <dir>...check out only these directories
add <dir>add another directory to the set
listshow the current set
disablego back to a full checkout
reapplyapply the set again after a merge or pull
--no-coneuse raw gitignore-style patterns instead of directories

git sparse-checkout set apps/web packages/ui

leaves the rest of the monorepo off your disk

git sparse-checkout list

shows which directories are present

git sparse-checkout disable

restores every file

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git sparse-checkout は何をしますか。

git 2.25で入った命令で、大きなリポジトリのうち指定したフォルダーだけをディスクに置きます。履歴は丸ごとあり、coneモードはグロブではなくフォルダー名を取ります。

Q. どう打ちますか。

git sparse-checkout set <dir>... — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-sparse-checkout