如何在将深度保持为1的同时在标记中初始化子模块

jan*_*anw 8 git git-submodules

对于普通的git仓库,你可以这样做:

git clone --branch 4.1.1 https://github.com/WordPress/WordPress.git . --depth 1
Run Code Online (Sandbox Code Playgroud)

这将在标签4.1.1上提供WP回购

对于一个子模块我确实得到了以下但我无法弄清楚如何只为一个标签.

git submodule add --depth 1  https://github.com/WordPress/WordPress.git wp
Run Code Online (Sandbox Code Playgroud)

如何在1个深度处将子模块签出到1个标签

我不介意之后再做一些命令,但如果可能的话,在一个命令中甚至更好.

TLDR: 我想要一个标签的子模块.哪个.git(/ module)文件夹尽可能小.

Von*_*onC 2

考虑到子模块可能不带有标签,您可能会想先这样做(如“可以进行 git submodule update 以获取子模块中的标签吗? ”中的建议):

\n\n
git submodule foreach --recursive \'git fetch --tags\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

但正如我在“ \xe2\x80\x9c \xe2\x80\x9dgit fetch --tagsgit fetch是否包含 \xe2\x80\x9c \xe2\x80\x9d? ”中解释的那样,这不仅会获取标签,还会获取所有标签 the associated commits (since git 1.9.0, February 2014)

\n\n

相反,您可以进入子模块,并获取深度为 1 的标签内容:

\n\n
git fetch --depth=1 origin refs/tags/<tag>:refs/tags/<tag>\ngit checkout <tag>\n
Run Code Online (Sandbox Code Playgroud)\n