如何 git 只克隆一个特定的标签而不获取整个 repo?

How to git clone a specific tag only without getting the whole repo?

我想获得 linux kernel 2.6.22.19 source 来为我的路由器交叉编译东西,但如果我这样做的话,回购协议是巨大的 (3gb)

git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

然后查看那个标签,克隆花了很长时间,我的带宽有限。

如果我运行这个

git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git --branch v2.6.22.19 --single-branch

接收到的文件大小约为 150mb,这是正确的处理方式吗,这个命令是什么意思? v2.6.22.19 是标签名称吗?为什么它可以在 --branch 之后添加?

克隆后。

[oglop@localhost linux-stable]$ git status
# Not currently on any branch.

提供 v2.6.22.19 是标签名称,git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git 是存储库 url,试试这个:

git clone --depth 1 --single-branch --branch v2.6.22.19 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

--depth 1 将只下载分支中的最新提交,这也有助于解决大小问题