git sparse-checkout
git
用法
git sparse-checkout set <dir>...git 2.25 加入的命令,只把你指定的目录留在磁盘上;历史仍是完整的,cone 模式接受目录名而不是 glob 通配符。
常用选项
| 选项 | 含义 |
|---|---|
| set <dir>... | check out only these directories |
| add <dir> | add another directory to the set |
| list | show the current set |
| disable | go back to a full checkout |
| reapply | apply the set again after a merge or pull |
| --no-cone | use raw gitignore-style patterns instead of directories |
示例
git sparse-checkout set apps/web packages/uileaves the rest of the monorepo off your disk
git sparse-checkout listshows which directories are present
git sparse-checkout disablerestores every file
难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. git sparse-checkout 是做什么的?
git 2.25 加入的命令,只把你指定的目录留在磁盘上;历史仍是完整的,cone 模式接受目录名而不是 glob 通配符。
Q. 怎么写?
git sparse-checkout set <dir>... —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 6 个,完整列表在 man git。这条命令属于git。
相关命令
man 手册: man git-sparse-checkout