2020年更新答案:
现在有一个命令git稀疏签出,我详细介绍了git 2.25(2020年Q1)
Nicono的回答说明了它的用法:
git sparse-checkout init --cone # to fetch only root files
git sparse-checkout add apps/my_app
git sparse-checkout add libs/my_lib
它随Git 2.27而发展,并且知道如何“重新应用”稀疏签出,就像这里一样。
注意,在Git 2.28中,Git状态会提示您处于稀疏签出的存储库中
注意/警告:某些在非锥模式下有效的稀疏签出模式会导致锥模式下的段错误,这已在Git 2.35 (Q1 2022)中得到纠正。
参见Derrick Stolee (derrickstolee)提交的commit a3eca58, commit 391c3a1, commit a481d43(2021年12月16日)。
(由Junio C Hamano—gitster—在commit 09481fe中合并,2022年1月10日)
稀疏检出:拒绝添加到不良模式
作者:Elijah Newren
署名:Derrick Stolee
When in cone mode sparse-checkout, it is unclear how 'git sparse-checkout'(man) add ... should behave if the existing sparse-checkout file does not match the cone mode patterns.
Change the behavior to fail with an error message about the existing patterns.
Also, all cone mode patterns start with a '/' character, so add that restriction.
This is necessary for our example test 'cone mode: warn on bad pattern', but also requires modifying the example sparse-checkout file we use to test the warnings related to recognizing cone mode patterns.
This error checking would cause a failure further down the test script because of a test that adds non-cone mode patterns without cleaning them up.
Perform that cleanup as part of the test now.
在Git 2.36 (Q2 2022)中,“Git稀疏签出”(man)希望使用每个工作树的配置,但在连接到裸存储库的工作树中不能很好地工作。
参见Derrick Stolee (derrickstolee)的commit 3ce1138, commit 5325591, commit 7316dc5, commit fe18733, commit 615a84a, commit 5c11c0d (07 Feb 2022)。
(由Junio C Hamano—gitster—在commit 6249ce2中合并,2022年2月25日)
工作树:复制添加上的稀疏签出模式和配置
署名:Derrick Stolee
作者:Elijah Newren
When adding a new worktree, it is reasonable to expect that we want to use the current set of sparse-checkout settings for that new worktree.
This is particularly important for repositories where the worktree would become too large to be useful.
This is even more important when using partial clone as well, since we want to avoid downloading the missing blobs for files that should not be written to the new worktree.
The only way to create such a worktree without this intermediate step of expanding the full worktree is to copy the sparse-checkout patterns and config settings during 'git worktree add'(man).
Each worktree has its own sparse-checkout patterns, and the default behavior when the sparse-checkout file is missing is to include all paths at HEAD.
Thus, we need to have patterns from somewhere, they might as well be the current worktree's patterns.
These are then modified independently in the future.
In addition to the sparse-checkout file, copy the worktree config file if worktree config is enabled and the file exists.
This will copy over any important settings to ensure the new worktree behaves the same as the current one.
The only exception we must continue to make is that core.bare and core.worktree should become unset in the worktree's config file.
原答案:2016年
git 2.9(2016年6月)将——no-checkout选项泛化到git工作树add(该命令允许在一个repo中使用多个工作树)
参见提交ef2a0ac(2016年3月29日)由Ray Zhang (OneRaynyDay)。
资助:Eric Sunshine (sunshineco)和Junio C Hamano (gitster)
(由Junio C Hamano—gitster—在commit 0d8683c中合并,2016年4月13日)
git工作树手册页现在包括:
--[no-]checkout:
默认情况下,添加签出<分支>,但是,——no-签出可以用来抑制签出,以便进行定制,例如配置稀疏签出。