← 返回命令列表

Linux command

git-sparse-checkout 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Enable sparse checkout and set directories

git sparse-checkout set [dir1] [dir2]

Add more directories to sparse checkout

git sparse-checkout add [dir]

List current sparse patterns

git sparse-checkout list

Reapply sparse patterns

git sparse-checkout reapply

Disable sparse checkout

git sparse-checkout disable

Check which paths match sparse rules

echo "[path/to/file]" | git sparse-checkout check-rules

Preview files outside sparse definition

git sparse-checkout clean --dry-run

说明

git sparse-checkout enables partial repository checkouts, where only specified directories and files are materialized in the working tree. This significantly reduces working directory size for large monorepos. Cone mode (the default) restricts patterns to directory-based inclusion, which is faster and simpler than full pattern matching. In cone mode, the set and add subcommands accept directory names rather than arbitrary gitignore patterns. Non-cone mode (--no-cone) allows arbitrary gitignore-style patterns but is deprecated due to poor performance and confusing semantics. This command is experimental. Its behavior may change in the future.

参数

--cone
Use cone mode for directory-based patterns (default, faster).
--no-cone
Use full pattern mode for arbitrary gitignore-style patterns.
--sparse-index
Enable sparse index format for improved performance.
--no-sparse-index
Disable sparse index format for compatibility with external tools.
--stdin
Read patterns from stdin (one per line) instead of arguments.
-f, --force
Allow cleaning without clean.requireForce config (for clean subcommand).
--dry-run
Preview what clean would remove without deleting anything.
--rules-file _file_
Match against rules in specified file instead of current rules (for check-rules).
-z
Use NUL-terminated paths for stdin and output (for check-rules).

FAQ

What is the git-sparse-checkout command used for?

git sparse-checkout enables partial repository checkouts, where only specified directories and files are materialized in the working tree. This significantly reduces working directory size for large monorepos. Cone mode (the default) restricts patterns to directory-based inclusion, which is faster and simpler than full pattern matching. In cone mode, the set and add subcommands accept directory names rather than arbitrary gitignore patterns. Non-cone mode (--no-cone) allows arbitrary gitignore-style patterns but is deprecated due to poor performance and confusing semantics. This command is experimental. Its behavior may change in the future.

How do I run a basic git-sparse-checkout example?

Run `git sparse-checkout set [dir1] [dir2]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --cone do in git-sparse-checkout?

Use cone mode for directory-based patterns (default, faster).