How to git clone a specific tag

后端 未结 5 1106
误落风尘
误落风尘 2020-11-28 18:03

From git-clone(1) Manual Page

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

5条回答
  •  时光取名叫无心
    2020-11-28 18:27

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

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

    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 , instead of --work-tree and --git-dir.

提交回复
热议问题