我有一些别名的子模块foreach’git co master; git up'(co& up分别是checkout& pull –rebase的别名.).
如何添加一个条件,如果子模块名称是Libraries / JSONKit,它会检出名为experimental的分支,而不是master?
传递给git子模块的脚本运行时,它的工作目录设置在给定子模块的顶部…所以你可以简单地看看pwd,看看你是否在你的特定子模块中.但是,如果您花一些时间阅读git子模块文档,结果会变得更加容易:
原文链接:https://www.f2er.com/bash/385113.htmlforeach 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.
所以你可以这样做:
git submodule foreach '[ "$path" = "Libraries/JSONKit" ] \ && branch=experimental \ || branch=master; git co $branch'