git - 我如何 "git clone"一个 repo,包括它的子模块?

标签 git git-submodules

我如何克隆一个 git 存储库以便它也克隆它的子模块?

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

最佳答案

在 Git 2.13 及更高版本中,可以使用 --recurse-submodules 代替 --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

对于已经克隆的 repos,或者旧的 Git 版本,使用:

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

关于git - 我如何 "git clone"一个 repo,包括它的子模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3796927/

相关文章:

git - 如何从 GITLAB 仪表板中新创建的 git 分支中删除特定文件和文件夹?

git - 路径 '.gitmodules' 在 '31627edc0c80332d93e694cb0ed379531fbc9de0' 中不存在

node.js - 使用 git 子模块导致发布时 npm 包大小太大

eclipse - 克隆一个有子模块的 git repo

git - 无法使用 fig/crane 在 Docker 容器中执行 git 命令

node.js - Heroku 部署错误上的 Webpack Node.js

python - 如何制作一个始终在 Linux 终端中运行的脚本?

git - 从 Git 存储库中删除用户名

git 按子文件夹拆分存储库并保留所有旧分支

docker - 无法在 Jenkins 的 docker 镜像中克隆子模块