gpt4 book ai didi

Git 子模块准备稀疏 checkout

转载 作者:太空狗 更新时间:2023-10-29 14:41:44 25 4
gpt4 key购买 nike

我有一个子模块用于稀疏 checkout 。如果没有稀疏 checkout ,我会做

git submodule update --init <path/to/submodule>

但是如何在不获取它(或获取它但不检查它)的情况下将子模块存储库初始化为空,以便我可以调用

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 .

最佳答案

您可以先尝试 as in here 将子模块克隆为普通存储库,然后再使用 git submodule absorbgitdirs

通过首先克隆深度为 1,您不会获得太多数据:

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

最后,只获取你想要的文件:

git submodule update --force --checkout <path/to/submodule>

正如 commentedJanus 一样,使用 git clone --filter 可以做得更好(更少的数据),我在 2019 年用“What is the git clone --filter option's syntax?”对此进行了说明:

#fastest clone possible:
git clone --filter=blob:none --no-checkout https://github.com/git/git
cd git
suburl=$(git config -f .gitmodules --get submodule.<sub>.url)
git submodule update --init --force --checkout <sub>

(用您的 <sub> 中的子模块名称条目替换 .gitmodules )

关于Git 子模块准备稀疏 checkout ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52780680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com