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