如何克隆git存储库,以便它也克隆其子模块?

运行gitclone$REPO_URL只会创建空的子模块目录。


当前回答

在填充子模块之前,您必须做两件事:

git submodule init 
git submodule update

其他回答

如何“git克隆”回购,包括其子模块?

(我把它作为一个独立的答案,因为我认为这在git中很重要)

可悲的是,但在很多情况下,那些不太知情的克隆人会错过外在的东西:

vc大便(https://github.com/dirk-thomas/vcstool)数字子报表(https://github.com/ingydotnet/git-subrepo)git链接(https://github.com/chronoxor/gil).gitsvnextmodule(由smartgit处理)。git外部(https://github.com/develer-staff/git-externals)git x模块(https://gitmodules.com/)等等

作为备份,无法创建裸克隆(--bare)+完全递归(--recursive)来镜像(--mirror)所有引用(而不仅仅是所有外部引用):使用--recursive和--bare克隆git存储库

因此,对于git,没有一种内置的方法可以完全接受外部依赖关系。这意味着没有一种方法可以完全备份任何随机git存储库。

如果子模块被添加到分支中,请确保将其包含在克隆命令中。。。

git clone -b <branch_name> --recursive <remote> <directory>

1.git子模块初始化2位子模块更新

或者可能git存储-ugit拉动原点主机数字存储p

在Git 2.13及更高版本中,可以使用--recurse子模块代替--recursive:

git clone --recurse-submodules -j8 git://github.com/foo/bar.git
cd bar

编者注:-j8是一种可选的性能优化,在2.8版中提供,并且一次并行获取最多8个子模块——参见man git clone。

Git 1.9版至2.12版(-j标志仅在2.8+版中可用):

git clone --recursive -j8 git://github.com/foo/bar.git
cd bar

在Git 1.6.5及更高版本中,您可以使用:

git clone --recursive git://github.com/foo/bar.git
cd bar

对于已克隆的repo或较旧的Git版本,请使用:

git clone git://github.com/foo/bar.git
cd bar
git submodule update --init --recursive

[快速回答]

您可以使用此命令克隆包含所有子模块的repo:

git clone --recursive YOUR-GIT-REPO-URL

或者,如果您已经克隆了项目,则可以使用:

git submodule init
git submodule update