我有一個包含許多子模塊的項目。我要循環使用下面的命令每個子模塊:在非零退出後繼續使用「git submodule foreach」命令循環子模塊
git submodule foreach npm install
而且我希望腳本繼續遍歷即使一個子模塊返回一個錯誤(不歸零碼),每個子模塊。目前,在任何子模塊中運行此命令的非零返回碼都會導致git停止對其餘子模塊的循環。
有關如何完成此任務的任何建議?
我有一個包含許多子模塊的項目。我要循環使用下面的命令每個子模塊:在非零退出後繼續使用「git submodule foreach」命令循環子模塊
git submodule foreach npm install
而且我希望腳本繼續遍歷即使一個子模塊返回一個錯誤(不歸零碼),每個子模塊。目前,在任何子模塊中運行此命令的非零返回碼都會導致git停止對其餘子模塊的循環。
有關如何完成此任務的任何建議?
只是讓你的命令總是返回0
代碼如下所示:
git submodule foreach 'npm install || :'
這是從手動拍攝: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.
命令:
從help :
在bash
:
:: :
Null command.
No effect; the command does nothing.
Exit Status:
Always succeeds.
總是成功:)
'git的子模塊的foreach「NPM安裝||真''會做同樣的事情。 –
它不適用於Windows。本來應該?即使使用bash,'
@MarceloFilho:嘗試使用git bash。 – MaBe
你可以看到這個topic。
我不使用GIT,但如果你能找到.gitmodules文件,它可以很容易循環每個子模塊:
<command to find all of your submodules>|while read; do
# ... (default use $REPLY as an item)
done
或者:
while read; do
# ...
done <<< "$(command to find all of your submodules)"
看到這個reminder on how to read a command output with a loop in Bash 。
git的子模塊的foreach '絲' – danday74