无法使用-b <tagname>直接克隆到git标记中

grm*_*grm 6 git

我有点疑惑为什么我无法直接从git clone命令检出标签.我尝试做的是:

git clone -b mytag <url>/foo.git
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

warning: Remote branch mytag not found in upstream origin, using HEAD instead
Run Code Online (Sandbox Code Playgroud)

标签存在,例如

cd foo && git checkout mytag 
Run Code Online (Sandbox Code Playgroud)

...效果很好.

如果有人可以分享为什么不可能直接克隆到标签,我会很感激.谢谢.

Bri*_*ips 4

也许您真正需要/想要做的就是使用git archive任何可以理解的东西来提取压缩包git rev-parse。您可以使用该--remote选项从某个远程源提取存档,<url>/foo.git该存档与您传递给克隆的值相同。理论上,这会快得多,因为您将获取的只是工作树而不是整个存储库。

这是一个“对我有用”的例子:

% git archive --prefix foo/ --remote <url>/foo.git my-tag | tar -xf -
Run Code Online (Sandbox Code Playgroud)