如何克隆多个特定的子模块? [英] How to clone multiple specific submodules?

查看:118
本文介绍了如何克隆多个特定的子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个脚本来克隆 Boost库,但是不幸的是,该存储库确实很大,我之后只需要使用一些子模块即可.我想将它们存储在这样的一个字符串变量中

I need to write a script to clone Boost library, but the repository is unfortunately really big and I need to use just some submodules afterwards. I'd like to store them in one string variable like this

MODULES="tools/build libs/system"

然后将变量传递给这样的一个命令

and then pass the variable in to one command like this

git clone --recurse-submodules=${MODULES} https://github.com/boostorg/boost.git

问题在于,在将多个参数传递给--recurse-submodules之后,所有参数都将被忽略.

The problem is, that after passing multiple arguments into --recurse-submodules, all of them get ignored.

我查看了如何仅更新特定的git子模块? ,但是答案仅涉及一个子模块的克隆或多次重复--recurse-submodules,而我不希望这样做,因为我想为脚本准备任意数量的子模块.

I had a look at How to only update specific git submodules?, but the answers cover only cloning of one submodules or repeating --recurse-submodules multiple times, which I don't like to, as I want to make the script prepared for arbitrary number of submodules.

有什么方法可以用Git实现吗?

Is there any way how to achieve that with Git?

推荐答案

您的想法是正确的,但不要使用变量,使用数组并以这种方式构建子模块.

Your idea is right, but don't use a variable, use an array and build your sub-modules that way.

modules=()
for mod in "tools/build" "libs/system"; do
    modules+=( --recurse-submodules="$mod" )
done

for循环中添加所有模块名称,以便每次迭代在其之前添加必填字段并生成完整的子模块数组.现在将其作为modules

In the for loop add all your modules names, so that each iteration adds the required fields before it and generates the complete sub-module array. Now pass it git clone as a quoted array expansion of modules

git clone "${modules[@]}" https://github.com/boostorg/boost.git

"${modules[@]}"扩展为上述步骤中生成的数组,每个生成的条目均由空格字符分隔.

The "${modules[@]}" expands to array generated in the step above, with each generated entry separated by a white-space character.

这篇关于如何克隆多个特定的子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆