如何在git中添加可选的子模块? [英] How to add optional submodules in git?

查看:248
本文介绍了如何在git中添加可选的子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当git存储库中有很多(例如20个)子模块时,我们可以像这样安装(并更新)它们:

When we have many (say 20) submodule in a git repository, we can install (and update) them like so:

git submodules update --init --recursive 

Git尝试在此命令之后(递归)下载每个子模块.如果我们要使某些子模块成为可选的(如插件)怎么办?

Git tries to download every submodule (recursively) after this command. What if we want to make some of the submodules optional (like a plugin)?

默认情况下,我们如何使git跳过下载这些可选子模块,并在将其标记为好,从现在开始使用"时作为常规子模块处理?

How can we make git skip downloading these optional submodules by default and handle as a usual submodule when we mark this submodule "okay, use this from now on"?

推荐答案

一种方法是:

  1. 获取仓库的子模块列表
  2. 获取每个子模块的用户输入(是否更新)
  3. 排除用户选择的子模块,
  4. 更新子模块

获取子模块列表

To get the list of submodules and format it to display only submodule path :

git submodule--helper list | awk '{$1=$2=$3=""; print substr($0,4)}'

排除子模块X :

git -c submodule."X".update=none submodule update --init --recursive

将这两个命令与xargs和 tr 实用程序结合在一起,并进一步使用命令替换,

Combining these two commands with xargs and tr utilities and further using command substitutition,

git $(git submodule--helper list | awk '{$1=$2=$3=""; print substr($0,4)}' | xargs -pI % echo -c submodule.\"%\".update=none | tr '\n' ' '| xargs echo) submodule update --init --recursive

xargs util的交互模式允许用户通过提供(y/n)格式的输入来选择要更新的子模块.输入y表示在更新期间排除了子模块.输入n表示未采取任何措施.

The interactive mode of xargs util allows user to select which submodule to update i.e by supplying input in (y/n) format. Input y indicates that submodule is excluded during the update. Input n indicates no action is taken.

注意:

  • 假定此处的子模块名称与其路径相同.但是,请在此处查看,以获取具有不同名称和路径的子模块名称.

  • The submodule name here is assumed to be the same as it's path. However, have a look here to get submodule names with diverging names and paths.

要(永久)排除或包含子模块X,应将属性submodule."X".update添加到

To exclude or include the submodule X (permanently), the attribute submodule."X".update should be added to the gitconfig file for the local repo. For exclusion set submodule."X".updateto none in the config file by using this command

 git config --local submodule."X".update none

并使用此命令取消设置

git config --local --unset submodule."X".update

  • 要排除嵌套子模块,请遵循

    这篇关于如何在git中添加可选的子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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