'git submodule update --init --recursive' VS 'git submodule foreach --recursive git submodule update --init'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24057871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:10:01  来源:igfitidea点击:

'git submodule update --init --recursive' VS 'git submodule foreach --recursive git submodule update --init'

gitgit-submodules

提问by Manish

I have git repo which has nested submodules. What is the difference between below 2 commands?

我有包含嵌套子模块的 git repo。以下2个命令有什么区别?

git submodule update --init --recursive

git submodule foreach --recursive git submodule update --init

回答by Martin

git submodule update --init --recursive

The submodule updatecommand will recurse into the registered submodules, update and init (if required) them and any nested submodules within.

submoduleupdate命令将递归到注册的子模块中,更新和初始化(如果需要)它们以及其中的任何嵌套子模块。

git submodule foreach --recursive git submodule update --init

foreachwill evaluate the command in each checked out submodule. So it will update and init (if required) each submodule and any nested submodules within due to --recursive.

foreach将评估每个检出的子模块中的命令。因此,它将更新和初始化(如果需要)每个子模块以及由于--recursive.

So in the end, both commands will achieve the same thing. Simply the execution differs, the first command won't step into each directory to execute the command.

所以最终,这两个命令都将实现相同的目标。只是执行不同,第一个命令不会进入每个目录执行命令。

回答by nickboldt

In my experience, the first one works. The second one does nothing.

根据我的经验,第一个有效。第二个什么都不做。

For a project like eclipse.platform.releng.aggregatorto initialize submodules so you can build, you need to clone all the child repos:

对于像eclipse.platform.releng.aggregator这样的项目来初始化子模块以便您可以构建,您需要克隆所有子存储库:

 git submodule update --init --recursive

回答by BrightestSirius

There exist differences!

存在差异!

 git submodule update --init --recursive

will register direct dependent submodules and clone them down, then go into next depth, register submodules and clone them recursively. Finally, all directly or indirectly dependent submodules will be registered and cloned from the remote. If there exists cyclic dependency, this command will never terminate.

将注册直接依赖的子模块并克隆它们,然后进入下一个深度,注册子模块并递归克隆它们。最后,所有直接或间接依赖的子模块都将从远程注册和克隆。 如果存在循环依赖,该命令将永不终止。

git submodule foreach --recursive git submodule update --init

This command follows the template:

此命令遵循模板:

git submodule foreach --recursive "your command"

which means that firstly, "git submodule foreach --recursive" will generate a submodules set, then in each submodule, your command gets executed. However for a initial project without executing "git submodule init" and then "git submodule update", "git submodule foreach --recursive" will be empty, so "your command" won't take place at all.

这意味着首先,“git submodule foreach --recursive”将生成一个子模块集,然后在每个子模块中执行您的命令。但是,对于没有执行“git submodule init”然后“git submodule update”的初始项目,“git submodule foreach --recursive”将为空,因此“您的命令”根本不会发生。