ma1*_*w28 9 git bash foreach git-submodules
我曾sup
化名为submodule foreach 'git co master; git up'
(co
&up
是别名checkout
和pull --rebase
,分别).
如何添加一个条件,如果子模块名称是Libraries/JSONKit
,它会检出名为的分支experimental
,而不是master
?
lar*_*sks 14
将passwd脚本git submodule
运行,将其工作目录设置为给定子模块的顶部...这样您就可以pwd
查看是否存在于特定子模块中.但是,如果您花一些时间阅读git 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.
Run Code Online (Sandbox Code Playgroud)
所以你可以这样做:
git submodule foreach '[ "$path" = "Libraries/JSONKit" ] \
&& branch=experimental \
|| branch=master; git co $branch'
Run Code Online (Sandbox Code Playgroud)
将以下内容添加到.git/config
:
[alias]
sup = "submodule foreach 'if [ $name == \"Libraries/JSONKit\" ]; then git co experimental; else git co master; fi; git up'"
Run Code Online (Sandbox Code Playgroud)