从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(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 --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
其他回答
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
克隆一个特定的标签,可能会返回“分离的HEAD”状态。
作为一种解决方法,首先尝试克隆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
注意:从Git 1.8.5开始,你可以使用-C <path>,而不是——work-tree和——Git -dir。
使用命令
git clone --help
查看git是否支持该命令
git clone --branch tag_name
如果没有,请执行以下步骤:
git clone repo_url
cd repo
git checkout tag_name
git clone --depth 1 --branch <tag_name> <repo_url>
——depth 1是可选的,但如果你只需要那个版本的状态,你可能想跳过下载那个版本之前的所有历史。
使用——single-branch选项只克隆历史导致标签的尖端。这样可以避免大量不必要的代码被克隆。
git clone <repo_url> --branch <tag_name> --single-branch