在遍历所有子模块列表时避免子模块
Avoiding submodules while looping through all list of submodules
我们有相当数量的子模块,我们想使用 git submodule foreach git <command>
遍历所有子模块。
发生的情况是这些子模块中有 1 个或 2 个不需要对它们使用这些命令,所以我想知道是否有办法避免循环先前指定的这些子模块。
... I was wondering if there could be a way to avoid looping these submodules previously specified.
不,没有。但是 git submodule foreach
运行s 任意 shell 命令,导出一些变量,如 described in the documentation:
foreach [--recursive] <command>
Evaluates an arbitrary shell command in each checked out submodule.
The command has access to the variables $name
, $sm_path
,
$displaypath
, $sha1
and $toplevel
: $name
is the name of the
relevant submodule section in .gitmodules
, $sm_path
is the path of
the submodule as recorded in the immediate superproject,
$displaypath
contains the relative path from the current working
directory to the submodules root directory, $sha1
is the commit as
recorded in the immediate superproject, and $toplevel
is the
absolute path to the top-level of the immediate superproject. Note
that to avoid conflicts with $PATH
on Windows, the $path
variable
is now a deprecated synonym of $sm_path
variable. ...
(我在这里做了一些小的格式指令更改,但文本应该或多或少匹配。您的 Git 版本可能有旧的 $path
名称而不是 $sm_path
, 取决于你 Git 的年龄。检查 你的 Git 的文档以确保:git help submodule
将打印出以上内容,作为一部分完整文档。)
由于您可以访问所有这些信息,使用它。选择最简单的方法来检查您的情况并跳过执行不适用的命令。不要一味地运行 git <em>foo</em>
;使用 if somecondition;然后 git <em>foo</em>; fi
或类似的.
我们有相当数量的子模块,我们想使用 git submodule foreach git <command>
遍历所有子模块。
发生的情况是这些子模块中有 1 个或 2 个不需要对它们使用这些命令,所以我想知道是否有办法避免循环先前指定的这些子模块。
... I was wondering if there could be a way to avoid looping these submodules previously specified.
不,没有。但是 git submodule foreach
运行s 任意 shell 命令,导出一些变量,如 described in the documentation:
foreach [--recursive] <command>
Evaluates an arbitrary shell command in each checked out submodule. The command has access to the variables
$name
,$sm_path
,$displaypath
,$sha1
and$toplevel
:$name
is the name of the relevant submodule section in.gitmodules
,$sm_path
is the path of the submodule as recorded in the immediate superproject,$displaypath
contains the relative path from the current working directory to the submodules root directory,$sha1
is the commit as recorded in the immediate superproject, and$toplevel
is the absolute path to the top-level of the immediate superproject. Note that to avoid conflicts with$PATH
on Windows, the$path
variable is now a deprecated synonym of$sm_path
variable. ...
(我在这里做了一些小的格式指令更改,但文本应该或多或少匹配。您的 Git 版本可能有旧的 $path
名称而不是 $sm_path
, 取决于你 Git 的年龄。检查 你的 Git 的文档以确保:git help submodule
将打印出以上内容,作为一部分完整文档。)
由于您可以访问所有这些信息,使用它。选择最简单的方法来检查您的情况并跳过执行不适用的命令。不要一味地运行 git <em>foo</em>
;使用 if somecondition;然后 git <em>foo</em>; fi
或类似的.