zhe*_*aus 4 git git-submodules
我正在尝试提交在几个子模块中所做的更改:
$ 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
.
Run Code Online (Sandbox Code Playgroud)
我看到进程在第一个最新的子模块上停止...但是,还有许多其他子模块具有暂存文件。如何使用唯一的命令提交在此类子模块中所做的更改?
简短版本,将命令更改为:
git submodule foreach "git commit -m 'fixed header guards' || :"
Run Code Online (Sandbox Code Playgroud)
更长的版本:正如手册页所述:
任何子模块中命令的非零返回都会导致处理终止。
并建议:
这可以通过添加 || 来覆盖 : 到命令末尾。
其作用是:
OR 列表的形式为
Run Code Online (Sandbox Code Playgroud)command1 || command2
command2当且仅当command1返回非零退出状态时才执行。AND 和 OR 列表的返回状态是列表中最后执行的命令的退出状态。
:bash 的:什么也不nop做,(并且总是)返回成功。
双引号引起来command的部分submodule foreach确保它全部作为单个参数传递git,并且您调用它的 shell 不会解析该|| :位本身。