How to git clone a specific tag

后端 未结 5 1101
误落风尘
误落风尘 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:25
    git clone --depth 1 --branch <tag_name> <repo_url>
    

    --depth 1 is optional but if you only need the state at that one revision, you probably want to skip downloading all the history up to that revision.

    0 讨论(0)
  • Use the command

    git clone --help
    

    to see whether your git supports the command

    git clone --branch tag_name
    

    If not, just do the following:

    git clone repo_url 
    cd repo
    git checkout tag_name
    
    0 讨论(0)
  • 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 <path>, instead of --work-tree and --git-dir.

    0 讨论(0)
  • 2020-11-28 18:37

    Use --single-branch option to only clone history leading to tip of the tag. This saves a lot of unnecessary code from being cloned.

    git clone <repo_url> --branch <tag_name> --single-branch
    
    0 讨论(0)
  • 2020-11-28 18:47
    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    
    

    Will be faster than :

    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
    

    Or

    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
    
    0 讨论(0)
提交回复
热议问题