如何克隆特定的Git标签

deikduxw  于 2023-02-18  发布在  Git
关注(0)|答案(7)|浏览(304)

git-clone(1) Manual Page开始
--branch也可以接受标记,并在结果存储库中分离该提交处的HEAD。
我试过了

git clone --branch <tag_name> <repo_url>

但它不起作用。它返回:

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

如何使用此参数?

nzk0hqpo

nzk0hqpo1#

git clone --depth 1 --branch <tag_name> <repo_url>

--depth 1是可选的,但是如果您只需要该版本的状态,则可能希望跳过下载该版本之前的所有历史记录。

x4shl7ld

x4shl7ld2#

使用--single-branch选项仅克隆导致标记提示的历史记录。这可以避免克隆大量不必要的代码。

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

nafvub8i3#

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
2o7dmzc5

2o7dmzc54#

git clone --depth 1 --branch <tag_name> <repo_url>

示例

git克隆--深度1 --分支0.37.2 https://github.com/apache/incubator-superset.git

<tag_name> : 0.37.2

<repo_url> : https://github.com/apache/incubator-superset.git
nqwrtyyt

nqwrtyyt5#

使用以下命令

git clone --help

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

git clone --branch tag_name

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

git clone repo_url 
cd repo
git checkout tag_name
wlsrxk51

wlsrxk516#

克隆特定标记时,可能返回**“detached HEAD”状态**。
作为一种解决方法,请尝试先克隆repo,然后 checkout 特定标记。例如:

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

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

stszievb

stszievb7#

我建议

git clone --depth 1 git@github.com:etlegacy/etlegacy.git --tags 2.80.2 --single-branch

相关问题