Git子模块准备稀疏签出 [英] Git submodule prepare for sparse checkout
问题描述
我有一个用于稀疏签出的子模块.没有稀疏的结帐,我会做
I have a submodule to be used with sparse checkout. Without sparse checkout I'd do
git submodule update --init <path/to/submodule>
但是如何在不获取子模块存储库的情况下将其初始化为空(或获取它,但不将其检出),所以我可以调用
but how to initialize the submodule repository empty without fetching it (or fetching it, but not checking it out) yet, so I can invoke
cd <path/to/submodule>
git config core.sparseCheckout true
cd <../../..>
echo <subdir-to-get> .git/modules/<path/to/submodule>/info/sparse-checkout
不幸的是
git submodule init <path/to/submodule>
不会在.git/modules/<path/to/submodule>
和文件<path/to/submodule>/.git
中创建存储库.
does not create the repository in .git/modules/<path/to/submodule>
and the file <path/to/submodule>/.git
.
推荐答案
您可以尝试如此处所示,首先将子模块克隆为普通存储库,然后使用 git submodule absorbgitdirs
.
You can try, as in here, to clone the submodule as normal repository first, and then use git submodule absorbgitdirs
.
通过首先以1的深度进行克隆,您不会得到太多数据:
By cloning first with a depth of 1, you don't get too many data:
git clone --depth=1 --no-checkout an/Url <path/to/submodule>
git submodule add an/Url <path/to/submodule>
git submodule absorbgitdirs
然后,您可以修改.git/modules/<path/to/submodule>/info/sparse-checkout
git -C <path/to/submodule> config core.sparseCheckout true
echo 'foo/*' >>.git/modules/<path/to/submodule>/info/sparse-checkout
最后,仅获取所需文件:
Finally, get only the files you want:
git submodule update --force --checkout <path/to/submodule>
这篇关于Git子模块准备稀疏签出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!