子模块内的 Git 子模块(嵌套子模块)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1535524/
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
Git submodule inside of a submodule (nested submodules)
提问by firstresponder
Is it possible for a git submodule to be made of several other git submodules, and the super git repo to fetch the contents for each submodule?
一个 git 子模块是否可以由其他几个 git 子模块组成,并且超级 git repo 可以为每个子模块获取内容?
I have tried to do this using the obvious/naive approach of creating a git repo holding several submodules.
我尝试使用明显/天真的方法来创建一个包含多个子模块的 git repo。
Then adding this git repo to another git repo as a submodule.
然后将此 git repo 作为子模块添加到另一个 git repo。
Then attempting to pull from the root directory of the super git repo by git submodule init
and then git submodule update
. But this fails to fetch the sub-submodules.
然后尝试从超级 git repo 的根目录中拉取git submodule init
,然后git submodule update
. 但这无法获取子子模块。
回答by inamiy
As mentioned in Retrospectively add --recursive to a git repo
正如回顾性地将 --recursive 添加到 git repo 中所述
git submodule update --init --recursive
should work.
应该管用。
回答by VonC
As Sridharcomments below, from Git1.6.5+, git clone --recursive
is now the official alternative, described in:
正如下面的Sridhar评论的那样,来自 Git1.6.5+,git clone --recursive
现在是官方替代品,描述如下:
- "
git clone --submodule
" - "Retrospectively add
--recursive
to a git repo"
(with thealias $ git config --global alias.cloner = 'clone --recursive'
, which avoids shadowing the normalgit clone
command)
- “
git clone --submodule
” - “回顾性添加
--recursive
到 git repo”
(使用alias $ git config --global alias.cloner = 'clone --recursive'
,避免隐藏正常git clone
命令)
inamiycorrectly points outthe git submodule update --init --recursive
command, introduced in commit b13fd5c, again in git1.6.5, by Johan Herland (jherland
).
inamiy正确地指出了git submodule update --init --recursive
在提交 b13fd5c 中引入的命令,同样在 git1.6.5 中,由Johan Herland ( jherland
)。
And IceFireadds in the comments:
If you would like to checkout only one submodule of a submodule, then
git submodule update --init <submoduleName>
is the way to go.
如果您只想签出一个子模块的一个子模块,那么
git submodule update --init <submoduleName>
就是要走的路。
(older original answer)
(较旧的原始答案)
According to the manual page
根据手册页
git submodule update --recursive
should update any nested submodules. But the init part may not be recursive.
应该更新任何嵌套的子模块。但是 init 部分可能不是递归的。
Depending on your version of Git, you could fall back to a more "scripting" approach, with this article Recursively Updating Git Submoduleswhich allows for recursive init and update:
根据您的 Git 版本,您可以退回到更“脚本化”的方法,这篇文章递归更新 Git 子模块,它允许递归初始化和更新:
#!/usr/bin/perl
use strict;
use Cwd;
init_and_update();
exit;
sub init_and_update
{
my $start_path = cwd();
my %paths;
my $updated;
do
{
my $data = `find . -name '.gitmodules'`;
chomp($data);
$data =~ s/\/\.gitmodules//g;
foreach my $path (split(/\n/, $data))
{
$paths{$path} = '' if($paths{$path} eq '');
}
$updated = 0;
foreach my $path (sort keys %paths)
{
if($paths{$path} eq '')
{
chdir($path);
`git submodule init 2>&1`;
`git submodule update 2>&1`;
chdir($start_path);
if($ARGV[0] eq '--remove-gitmodules')
{
unlink("$path/.gitmodules");
}
$paths{$path} = 1;
$updated++;
}
}
} while($updated);
}