继续遍历针对&quot子模块,子模块的git的foreach"一个非零退出后命令 [英] Continue looping over submodules with the "git submodule foreach" command after a non-zero exit

查看:623
本文介绍了继续遍历针对&quot子模块,子模块的git的foreach"一个非零退出后命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多子模块的项目。我想循环每个子模块使用下面的命令:

I have a project that contains many submodules. I want to loop over each submodule with the following command:

git的子模块的foreach NPM安装

和我想的脚本继续遍历即使其中一个子模块返回一个错误(非归零$ C $三)各子模块。目前,在所有子模块运行此命令非零返回code会导致混帐停止循环在其余子模块。

And I want the script to continue looping over each submodule even if one submodule returns an error (non zero return code). Currently, a non-zero return code from running this command in any submodule will cause git to stop looping over the remaining submodules.

这是如何做到这一点的任何建议?

Any recommendations on how to accomplish this?

推荐答案

只是让你的命令总是返回 0 code,像这样:

Just make your command always return a 0 code like so:

git submodule foreach 'npm install || :'

这是从手动拍摄: git的帮助子模块

This is taken from the manual: git help submodule:

   foreach
       Evaluates an arbitrary shell command in each checked out submodule.
       The command has access to the variables $name, $path, $sha1 and
       $toplevel: $name is the name of the relevant submodule section in
       .gitmodules, $path is the name of the submodule directory relative
       to the superproject, $sha1 is the commit as recorded in the
       superproject, and $toplevel is the absolute path to the top-level
       of the superproject. Any submodules defined in the superproject but
       not checked out are ignored by this command. Unless given --quiet,
       foreach prints the name of each submodule before evaluating the
       command. If --recursive is given, submodules are traversed
       recursively (i.e. the given shell command is evaluated in nested
       submodules as well). A non-zero return from the command in any
       submodule causes the processing to terminate. This can be
       overridden by adding || : to the end of the command.

       As an example, git submodule foreach 'echo $path `git rev-parse
       HEAD`' will show the path and currently checked out commit for each
       submodule.

命令帮助:庆典

:: :
    Null command.

    No effect; the command does nothing.

    Exit Status:
    Always succeeds.

总是成功:)

这篇关于继续遍历针对&quot子模块,子模块的git的foreach"一个非零退出后命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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