如何 git clone 特定标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20280726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:24:01  来源:igfitidea点击:

How to git clone a specific tag

gitgit-clonegit-tag

提问by Jiang Jun

From git-clone(1) Manual Page

来自git-clone(1) 手册页

--branchcan also take tags and detaches the HEAD at that commit in the resulting repository.

--branch还可以在结果存储库中的该提交中获取标签并分离 HEAD。

I tried

我试过

git clone --branch <tag_name> <repo_url>

But it does not work. It returns:

但它不起作用。它返回:

warning: Remote branch 2.13.0 not found in upstream origin, using HEAD instead

How to use this parameter?

这个参数怎么用?

回答by Erik Saunier

git clone --branch <tag_name> <repo_url>

This command is not supported in git 1.7.9.5.

git 1.7.9.5 不支持此命令。

I use git 1.8.3.5 and it works

我使用 git 1.8.3.5 并且它有效

回答by Sahil kalra

Use --single-branchoption to only clone history leading to tip of the tag. This saves a lot of unnecessary code from being cloned.

使用--single-branch选项仅克隆导致标签尖端的历史记录。这可以避免克隆许多不必要的代码。

git clone <repo_url> --branch <tag_name> --single-branch

回答by RzR

git clone -b 13.1rc1-Gotham  --depth 1  https://github.com/xbmc/xbmc.git
Cloning into 'xbmc'...
remote: Counting objects: 17977, done.
remote: Compressing objects: 100% (13473/13473), done.
Receiving objects:  36% (6554/17977), 19.21 MiB | 469 KiB/s    

Will be faster than :

将比:

git clone https://github.com/xbmc/xbmc.git
Cloning into 'xbmc'...
remote: Reusing existing pack: 281705, done.
remote: Counting objects: 533, done.
remote: Compressing objects: 100% (177/177), done.
Receiving objects:  14% (40643/282238), 55.46 MiB | 578 KiB/s

Or

或者

git clone -b 13.1rc1-Gotham  https://github.com/xbmc/xbmc.git
Cloning into 'xbmc'...
remote: Reusing existing pack: 281705, done.
remote: Counting objects: 533, done.
remote: Compressing objects: 100% (177/177), done.
Receiving objects:  12% (34441/282238), 20.25 MiB | 461 KiB/s

回答by mathsyouth

Use the command

使用命令

git clone --help

to see whether your git supports the command

查看你的git是否支持该命令

git clone --branch tag_name

If not, just do the following:

如果没有,只需执行以下操作:

git clone repo_url 
cd repo
git checkout tag_name

回答by Noam Manos

Cloning a specific tag, might return 'detached HEAD' state.

克隆一个特定的标签,可能会返回'detached HEAD' state

As a workaround, try to clone the repo first, and then checkout a specific tag. For example:

作为解决方法,尝试先克隆 repo,然后签出特定标签。例如:

repo_url=https://github.com/owner/project.git
repo_dir=$(basename $repo_url .git)
repo_tag=0.5

git clone --single-branch $repo_url # using --depth 1 can show no tags
git --work-tree=$repo_dir --git-dir=$repo_dir/.git checkout tags/$repo_tag

Note: Since Git 1.8.5, you can use -C <path>, instead of --work-treeand --git-dir.

注意:从 Git 1.8.5 开始,您可以使用-C <path>, 代替--work-treeand --git-dir