git 可以給倉庫歷史中的某一個提交點打上標(biāo)簽,常常用于標(biāo)記發(fā)布結(jié)點( 比如:v1.0 、 v2.0 等)。在本節(jié)中,你將會學(xué)習(xí)如何列出已有的標(biāo)簽、如何創(chuàng)建和刪除新的標(biāo)簽、以及不同類型的標(biāo)簽分別是什么。
如果我們要查看所有標(biāo)簽可以使用以下命令:
git tag
例如:
$ git tag v0.9 v1.0
添加標(biāo)簽的語法:
git tag -a (tagname)
例如:
$ git tag -a v1.0
當(dāng)你執(zhí)行 git tag -a 命令時,Git 會打開你的編輯器,讓你寫一句標(biāo)簽注解,就像你給提交寫注解一樣。
現(xiàn)在,注意當(dāng)我們執(zhí)行 git log --decorate 時,我們可以看到我們的標(biāo)簽了:
commit a097a65e501fa4c15297c9663c24affbada4eb2a (HEAD -> master, tag: v1.0) Author: cainiaoplusDate: Sun May 9 15:29:40 2021 +0800 this is v1.0 tag.
如果我們忘了給某個提交打標(biāo)簽,又將它發(fā)布了,我們可以給它追加標(biāo)簽。
例如,假設(shè)我們發(fā)布了提交 85fc7e7,但是那時候忘了給它打標(biāo)簽。
我們現(xiàn)在也可以補打標(biāo)簽:
$ git tag -a v0.9 85fc7e7 $ git log --oneline --decorate --graph * d5e9fc2 (HEAD -> master) Merge branch 'hotfix' |\ | * 7774248 (hotfix) changed the test.txt * | c68142b 修改代碼 |/ * 3e92c19 add test.txt * 3b58100 (tag: v0.9) 第一次版本提交
git tag -a (tagname) -m (message)
例如,添加一個 v1.0 標(biāo)簽,同時附加備注信息 “It is a cainiaoplus.com tag”:
git tag -a v1.0 -m "It is a cainiaoplus.com tag"
git tag -d (tagname)
例如:
$git tag -d v1.0 Deleted tag 'v1.0' (was 403cd05)
git show (tagname)
例如:
$git show v1.0 commit a83516d0fb5da5fd5ad749733a160219b5a5ceac (tag: v1.0) Author: cainiaoplus
git push origin (tagname)
將 tagname 標(biāo)簽推送到遠程版本庫。