使用 only 命令提交子模块中的更改
commit changes in the submodules with the only command
我正在尝试提交在几个子模块中所做的更改:
$ git submodule foreach git commit -m 'fixed header guards'
Entering 'libs/BaseDisplay'
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
fatal: run_command returned non-zero status for libs/BaseDisplay
.
我看到进程在第一个最新的子模块上停止...
但是,还有许多其他具有暂存文件的子模块。
如何使用唯一命令提交在此类子模块中所做的更改?
简短版本,将您的命令更改为:
git submodule foreach "git commit -m 'fixed header guards' || :"
更长的版本:如手册页所述:
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.
这是做什么的:
An OR list has the form
command1 || command2
command2
is executed if, and only if, command1
returns a non-zero exit status. The return status of AND and OR lists is the exit status of the last command executed in the list.
而 :
是 bash 的 nop
:什么都不做,(总是)return 成功。
submodule foreach
的 command
部分周围的双引号确保它全部作为单个参数传递给 git
并且您从中调用它的 shell不解析 || :
位本身。
我正在尝试提交在几个子模块中所做的更改:
$ git submodule foreach git commit -m 'fixed header guards'
Entering 'libs/BaseDisplay'
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
fatal: run_command returned non-zero status for libs/BaseDisplay
.
我看到进程在第一个最新的子模块上停止... 但是,还有许多其他具有暂存文件的子模块。 如何使用唯一命令提交在此类子模块中所做的更改?
简短版本,将您的命令更改为:
git submodule foreach "git commit -m 'fixed header guards' || :"
更长的版本:如手册页所述:
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.
这是做什么的:
An OR list has the form
command1 || command2
command2
is executed if, and only if,command1
returns a non-zero exit status. The return status of AND and OR lists is the exit status of the last command executed in the list.
而 :
是 bash 的 nop
:什么都不做,(总是)return 成功。
submodule foreach
的 command
部分周围的双引号确保它全部作为单个参数传递给 git
并且您从中调用它的 shell不解析 || :
位本身。