Bash:Git submodule foreach?

ma1*_*w28 9 git bash foreach git-submodules

我曾sup化名为submodule foreach 'git co master; git up'(co&up是别名checkoutpull --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)

  • 对于那里的任何googlers,我将其改编为嵌套子模块`git submodule foreach'git submodule init && git submodule update'` - 发现它使得有大量插件的项目更容易生活;) (2认同)

ma1*_*w28 1

将以下内容添加到.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)