Van git-clone(1) handmatige pagina
--branch
kan ook tags nemen en de HEAD ontkoppelen bij die commit in de resulterende repository.
Ik heb het geprobeerd
git clone --branch <tag_name> <repo_url>
Maar het werkt niet. Het geeft terug:
warning: Remote branch 2.13.0 not found in upstream origin, using HEAD instead
Hoe deze parameter te gebruiken?
Antwoord 1, autoriteit 100%
git clone --depth 1 --branch <tag_name> <repo_url>
--depth 1
is optioneel, maar als je alleen de status van die ene revisie nodig hebt, wil je waarschijnlijk de hele geschiedenis tot aan die revisie overslaan.
Antwoord 2, autoriteit 17%
Gebruik de optie --single-branch
om alleen de geschiedenis te klonen die leidt tot de tip van de tag. Dit voorkomt dat er veel onnodige code wordt gekloond.
git clone <repo_url> --branch <tag_name> --single-branch
Antwoord 3, autoriteit 7%
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
Wordt sneller dan:
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
Of
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
Antwoord 4
Gebruik het commando
git clone --help
om te zien of je git het commando ondersteunt
git clone --branch tag_name
Zo niet, doe dan het volgende:
git clone repo_url
cd repo
git checkout tag_name
Antwoord 5
git clone --depth 1 --branch <tag_name> <repo_url>
Voorbeeld
git kloon –diepte 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
Antwoord 6
Als een specifieke tag wordt gekloond, kan de status ‘detached HEAD’worden geretourneerd.
Probeer als tijdelijke oplossing eerst de opslagplaats te klonen en vervolgens een specifieke tag af te rekenen. Bijvoorbeeld:
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
Opmerking: sinds Git 1.8.5, kunt u -C <path>
gebruiken in plaats van --work-tree
en --git-dir
.