Bash:Git submodule foreach?
发布时间:2020-12-15 18:24:56 所属栏目:安全 来源:网络整理
导读:我有一些别名的子模块foreach’git co master; git up'(co up分别是checkout pull –rebase的别名.). 如何添加一个条件,如果子模块名称是Libraries / JSONKit,它会检出名为experimental的分支,而不是master? 传递给git子模块的脚本运行时,它的工作目录设置
我有一些别名的子模块foreach’git co master; git up'(co& up分别是checkout& pull –rebase的别名.).
如何添加一个条件,如果子模块名称是Libraries / JSONKit,它会检出名为experimental的分支,而不是master?
传递给git子模块的脚本运行时,它的工作目录设置在给定子模块的顶部…所以你可以简单地看看pwd,看看你是否在你的特定子模块中.但是,如果您花一些时间阅读git子模块文档,结果会变得更加容易:
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. 所以你可以这样做: git submodule foreach '[ "$path" = "Libraries/JSONKit" ] && branch=experimental || branch=master; git co $branch' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |