简体   繁体   English

git CLI 如何执行同时更新所有子模块的结账?

[英]git CLI how do I perform a checkout that also updates all of the submodules?

So I can clone a branch and get all the submodules with:所以我可以克隆一个分支并获取所有子模块:

git clone <url> -b myBranch --recursive

This is great :) But then I want to switch to a different branch, so I do:这很棒 :) 但是后来我想切换到另一个分支,所以我这样做:

git checkout myBranch2

This updated the top-level of my project, but not the submodules (I did not see a recursive option here).这更新了我项目的顶层,但没有更新子模块(我在这里没有看到递归选项)。 Infact I got an output that suggests it knows that the submodules need updating, but I just don't know how to do that part:事实上,我得到一个输出,表明它知道子模块需要更新,但我只是不知道如何做那部分:

c:\dev> git checkout myBranch2
M        SubModule1
M        SubModule2
Branch myBranch2 set up to track remote branch myBranch2 from origin.
Switched to a new branch 'myBranch2'

So then I checked the version of the SubModule1 and it is still pointing to the version that was originaly checked out (the latest) and not the version it should be pointing to (about 3 checkins older) that was associated with the branch myBranch2.然后我检查了 SubModule1 的版本,它仍然指向最初检出的版本(最新),而不是它应该指向的与分支 myBranch2 相关联的版本(大约 3 个更旧的签入)。

Of course I could just clone a new one and have both - this is what I would normally do, but it bugs me that I don't know how to do this... and it might be useful.当然,我可以克隆一个新的并同时拥有两者 - 这是我通常会做的事情,但是我不知道如何做到这一点让我感到烦恼......这可能很有用。

After git checkout run git checkout运行后

git submodule update --checkout --recursive

From git submodule documentation:git submodule文档:

git submodule update ...

Update the registered submodules to match what the superproject expects by cloning missing submodules and updating the working tree of the submodules.通过克隆丢失的子模块并更新子模块的工作树来更新已注册的子模块以匹配超级项目的期望。 The "updating" can be done in several ways depending on command line options and the value of submodule.<name>.update configuration variable. “更新”可以通过多种方式完成,具体取决于命令行选项和submodule.<name>.update配置变量的值。 Supported update procedures are:支持的更新程序有:

  • checkout - the commit recorded in the superproject will be checked out in the submodule on a detached HEAD . checkout - 记录在超级项目中的提交将在分离的HEAD上的子模块中检出。 This is done when --checkout option is given, or no option is given, and submodule.<name>.update is unset, or if it is set to checkout .这是在给出--checkout选项时完成的,或者没有给出选项,并且submodule.<name>.update未设置,或者如果它被设置为checkout

  • ... ...

--recursive

This option is only valid for foreach , update , status and sync commands.此选项仅对foreachupdatestatussync命令有效。 Traverse submodules recursively.递归遍历子模块。 The operation is performed not only in the submodules of the current repo, but also in any nested submodules inside those submodules (and so on).该操作不仅在当前 repo 的子模块中执行,而且在这些子模块内的任何嵌套子模块中执行(等等)。

You can also set up a post-checkout hook so that updating of submodules is performed automatically.您还可以设置一个post-checkout挂钩,以便自动执行子模块的更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM