如何克隆一个特定的标签

从git-clone(1)手册页

--branch也可以取得标签,并在生成的仓库提交时分离HEAD。

我试过了

 git clone --branch <tag_name> <repo_url> 

但它不起作用。 它返回:

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

如何使用这个参数?

 git clone --branch <tag_name> <repo_url> 

这个命令在git 1.7.9.5中不被支持。

我使用git 1.8.3.5,它的工作原理

使用--single-branch选项只克隆导致标签顶端的历史logging 。 这节省了大量不必要的代码被克隆。

 git clone <repo_url> --branch <tag_name> --single-branch 
 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 

会比以下更快:

 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 

要么

 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 

使用该命令

 git clone --help 

看看你的git是否支持这个命令

 git clone --branch tag_name 

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

 git clone repo_url cd repo git checkout tag_name