[英]Git submodules checkout to branch if not exist then switch to another
我想要类似的东西:
git submodule foreach --recursive git checkout some_feature_branch || git checkout develop
所以如果some_feature_branch
存在,那么我想检查它,否则develop
。 是否可以使用内置的git
或bash
命令来实现它?
请记住, git submodule foreach
将其参数传递给 shell,因此您所要做的就是提供正确的 shell 命令。 但是,如果您在shell(命令行解释器)中键入命令,则shell 将决定您的意思。 命令:
foo some bars || raz a matazz
意味着,到 shell:
这不是你想要的。 You want git submodule
itself to try to git checkout
and if that fails, you want git submodule
your main shell—to go on to git checkout
. 也就是说,您不希望:
你要:
所以那是:
git submodule foreach "git checkout a || git checkout b"
这里的双引号(尽管单引号也可以)保护||
因此顶级shell不会尝试将其解释为:
(git submodule foreach git checkout a) || (git checkout b)
相反,顶层 shell 将整个“git checkout a || git checkout b”部分传递给git submodule foreach
命令。 该命令 - git submodule foreach
- 然后通过git checkout a || git checkout b
git checkout a || git checkout b
到一个命令行解释器为一个子模块运行。 然后git submodule foreach
继续下一个子模块。
(Note that this has very little to do with Git itself: it's basic shell programming. The shell is an interpreter that runs shell programs, and you need to learn to write programs for it.)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.