--branch
也可以在生成的存储库中获取标记并分离该提交的HEAD。
我试过
git clone --branch <tag_name> <repo_url>
但它不起作用。它返回:
warning: Remote branch 2.13.0 not found in upstream origin, using HEAD instead
如何使用此参数?
答案 0 :(得分:202)
git clone --branch <tag_name> <repo_url>
git 1.7.9.5不支持此命令。
我使用git 1.8.3.5并且它可以正常工作
答案 1 :(得分:48)
使用--single-branch
选项仅克隆导致标记提示的历史记录。这样就可以节省大量不必要的代码。
git clone <repo_url> --branch <tag_name> --single-branch
答案 2 :(得分:28)
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
答案 3 :(得分:2)
git clone --depth 1 --branch <tag_name> <repo_url>
示例
<块引用>git clone --depth 1 --branch 0.37.2 https://github.com/apache/incubator-superset.git
<tag_name> : 0.37.2
<repo_url> : https://github.com/apache/incubator-superset.git
答案 4 :(得分:1)
使用命令
git clone --help
查看你的git是否支持命令
git clone --branch tag_name
如果没有,请执行以下操作:
git clone repo_url
cd repo
git checkout tag_name
答案 5 :(得分:0)
克隆特定标签可能会返回“分离头”状态。
作为解决方法,请尝试首先克隆存储库,然后签出特定标签。例如:
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
。
答案 6 :(得分:-1)
git clone -b brachName RepoUrl tagName