像其他版本控制系統(tǒng)(VCS)一樣礁遣,Git 可以給歷史中的某一個(gè)提交打上標(biāo)簽乞榨,以示重要。 比較有代表性的是人們會(huì)使用這個(gè)功能來標(biāo)記發(fā)布結(jié)點(diǎn)
情形一: 列出標(biāo)簽
命令:
git tag
列出taggit tag -l "v0.0.*"
搜索v0.0系列的tag
? git_test git:(master) git tag -a v0.1.0 -m "測(cè)試標(biāo)簽"
? git_test git:(master) git tag
v0.0.1-rc0
v0.1.0
? git_test git:(master) git tag -l "v0.0.*"
v0.0.1-rc0
情形二: 創(chuàng)建標(biāo)簽
Git 使用兩種主要類型的標(biāo)簽:輕量標(biāo)簽(lightweight)與附注標(biāo)簽(annotated)拆融。
一個(gè)輕量標(biāo)簽很像一個(gè)不會(huì)改變的分支 - 它只是一個(gè)特定提交的引用染突。
然而,附注標(biāo)簽是存儲(chǔ)在 Git 數(shù)據(jù)庫(kù)中的一個(gè)完整對(duì)象姻僧。 它們是可以被校驗(yàn)的规丽;其中包含打標(biāo)簽者的名字蒲牧、電子郵件地址、日期時(shí)間嘁捷;還有一個(gè)標(biāo)簽信息造成;并且可以使用 GNU Privacy Guard (GPG)簽名與驗(yàn)證。 通常建議創(chuàng)建附注標(biāo)簽雄嚣,這樣你可以擁有以上所有信息晒屎;但是如果你只是想用一個(gè)臨時(shí)的標(biāo)簽,或者因?yàn)槟承┰虿幌胍4婺切┬畔⒒荷p量標(biāo)簽也是可用的鼓鲁。
創(chuàng)建附注標(biāo)簽
? git_test git:(master) git tag -a v0.1.1 -m "測(cè)試標(biāo)簽"
? git_test git:(master) git tag
v0.0.1-rc0
v0.1.0
v0.1.1
查看標(biāo)簽信息與對(duì)應(yīng)的提交信息
? git_test git:(master) git show v0.1.1
tag v0.1.1
Tagger: augustine <cto@5dcto.com>
Date: Thu Oct 13 16:19:09 2016 +0800
測(cè)試標(biāo)簽
commit b6199c8df83ccb70a940d90c9621bcc43d025f1e
Author: augustine <cto@5dcto.com>
Date: Wed Oct 12 14:59:30 2016 +0800
test
diff --git a/2 b/2
index e69de29..14be0d4 100644
--- a/2
+++ b/2
創(chuàng)建輕量標(biāo)簽
? git_test git:(master) git tag v1.0.1
? git_test git:(master) git tag
v0.0.1-rc0
v0.1.0
v0.1.1
v1.0.1
查看輕量標(biāo)簽
commit b6199c8df83ccb70a940d90c9621bcc43d025f1e
Author: augustine <cto@5dcto.com>
Date: Wed Oct 12 14:59:30 2016 +0800
test
diff --git a/2 b/2
index e69de29..14be0d4 100644
--- a/2
+++ b/2
情形三: 后期打標(biāo)簽
可以對(duì)過去的提交打標(biāo)簽。
? git_test git:(master) git log --pretty=oneline
b6199c8df83ccb70a940d90c9621bcc43d025f1e test
7dc31d13d7d48a7e1cd93f31668bd50beb679889 測(cè)試 ament
e87932d0c46461dcf77fd75feef2a3c7b28e4fe4 renamed
10ff61af1a6aea266a423222decc0dfc4be67ad8 rename
d446522b785cc96b6161b91f35f0362eaffde7d4 rename
782be0944b2e3b086fc13604dfece14b7512773f test
4021312cdb038da674f6a85a5a3b358f012209dc save last commit
? git_test git:(master) git tag -a v0.0.1-rc00 e87932d0c46461dcf77fd75feef2a3c7b28e4fe4
1 測(cè)試補(bǔ)打標(biāo)簽
2 # Write a message for tag:
3 # v0.0.1-rc00
4 # Lines starting with '#' will be ignored.
? git_test git:(master) git tag
v0.0.1-rc0
v0.0.1-rc00
v0.1.0
v0.1.1
v1.0.1
情形四: 共享標(biāo)簽
默認(rèn)情況下港谊,
git push
命令并不會(huì)傳送標(biāo)簽到遠(yuǎn)程倉(cāng)庫(kù)服務(wù)器上骇吭。 在創(chuàng)建完標(biāo)簽后你必須顯式地推送標(biāo)簽到共享服務(wù)器上。 這個(gè)過程就像共享遠(yuǎn)程分支一樣 - 你可以運(yùn)行git push origin [tagname]
歧寺。如果想要一次性推送很多標(biāo)簽燥狰,也可以使用帶有
--tags
選項(xiàng)的git push
命令。 這將會(huì)把所有不在遠(yuǎn)程倉(cāng)庫(kù)服務(wù)器上的標(biāo)簽全部傳送到那里斜筐。
? git_test git:(master) git push origin v0.0.1-rc0
Username for 'https://github.com': xuguotao1984@163.com
Password for 'https://xuguotao1984@163.com@github.com':
Counting objects: 1, done.
Writing objects: 100% (1/1), 158 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/xuguotao/git_test.git
* [new tag] v0.0.1-rc0 -> v0.0.1-rc0
? git_test git:(master) git push --tag
Username for 'https://github.com': xuguotao1984@163.com
Password for 'https://xuguotao1984@163.com@github.com':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 375 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/xuguotao/git_test.git
* [new tag] v0.0.1-rc00 -> v0.0.1-rc00
* [new tag] v0.1.0 -> v0.1.0
* [new tag] v0.1.1 -> v0.1.1
* [new tag] v1.0.1 -> v1.0.1
情形五: 檢出標(biāo)簽
在 Git 中你并不能真的檢出一個(gè)標(biāo)簽龙致,因?yàn)樗鼈儾⒉荒芟穹种б粯觼砘匾苿?dòng)。 如果你想要工作目錄與倉(cāng)庫(kù)中特定的標(biāo)簽版本完全一樣顷链,可以使用
git checkout -b [branchname] [tagname]
在特定的標(biāo)簽上創(chuàng)建一個(gè)新分支
? git_test git:(master) git checkout -b v0.1.1
Switched to a new branch 'v0.1.1'
? git_test git:(v0.1.1) gst
On branch v0.1.1
nothing to commit, working directory clean