【问题标题】:git -submodules / repo - How to use commit and branch for a bunch of branches in separate modules?git -submodules / repo - 如何在单独的模块中为一堆分支使用提交和分支?
【发布时间】:2013-01-13 14:16:21
【问题描述】:

我有 repo 包装器和大约十几个不同的 git 存储库。

我想要一个可以稍后应用/使用的补丁 以下列方式:

我想对所有更改的子模块执行此命令:

git checkout -b all_sub_branch
git commit -a all_submodules
git format-patch all_submodules aaa.patch
git apply aaa.patch

【问题讨论】:

    标签: git git-submodules repository


    【解决方案1】:

    普通的 git 答案(使用子模块):

    为每个子模块完成的这种过程可以通过以下方式启动:

    git submodule foreach [--recursive] ...
    

    使用 '...' 指代一个包含所有命令的 git 别名。

    来自git submodule man page

    foreach
    

    在每个签出的子模块中评估任意 shell 命令。
    该命令可以访问变量$name$path$sha1$toplevel

    • $name.gitmodules中相关子模块部分的名称,
    • $path 是相对于超项目的子模块目录的名称,
    • $sha1 是超级项目中记录的提交,并且
    • $toplevel 是超级项目顶层的绝对路径。

    此命令忽略在超级项目中定义但未检出的任何子模块。
    除非给定--quiet,否则foreach 会在评估命令之前打印每个子模块的名称。
    如果给定--recursive,则递归遍历子模块(即,给定的shell命令也在嵌套子模块中进行评估)。


    问题在于 android repo wrapper command 以自己独特的方式完成 git 子模块的工作。
    所以git submodule foreach 的等价物可能是:repo forall,例如:

    repo forall -c 'git status'

    【讨论】:

    • 我如何使用 repo 来做到这一点?
    • @0x90 您无法立即执行此操作,因为该 repo 命令不会维护父 repo 与其“项目”之间的 git 子模块链接。我已经编辑了答案以包含一个可能的“repo”命令。
    猜你喜欢
    • 2016-09-24
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 2019-08-22
    • 2020-03-24
    • 2021-06-28
    • 2018-07-17
    相关资源
    最近更新 更多