git 跟其它版本控制系统一样,可以打标签 (tag), 作用是标记一个点为一个版本号,如 1.3, v1.0, ver_0.1.3. 在程序开发到一个阶段后,我们需要打个标签,发布一个版本.
1、创建标签
切换到需要打标签的分支上,使用命令 git tag 就可以打一个标签,默认标签是打在最新提交的commit上的。
(1)不带说明的标签:
$ git tag <tagname>
例如:
$ git tag v1.0
(2)带说明的标签:用-a指定标签名,-m指定说明文字。
$ git tag -a <tagname> -m “说明文字”
例如:
$ git tag -a v1.0 -m“version 1.0”
(3)指定历史提交(commit_id)的标签:
$ git tag <tagname> commit_id
和
$ git tag -a <tagname> -m “说明文字” commit_id
2、查看标签
(1)查看所有标签:
$ git tag
这个列表是按照字母表顺序给出,而不是按时间顺序给出的。例如:
$git tag
v0.7
v0.8
v0.9
v1.0
(2)查看某个标签信息:
$ git show <tagname>
使用 git show 命令查看相应标签的版本信息,并连同显示打标签时的提交对象。例如:
$git show v0.9
commit 176abf86dad7679eb7a0d3a3f1080e0c83467479
Author: vorlcher <vorlcher@abc.com>
Date: Fri Feb 26 09:47:31 2016 +0800
添加文件:CustomerService
diff --git a/CustomerService/.idea/.name b/CustomerService/.idea/.name
index a7364cc..d4dd2f3 100644
--- a/CustomerService/.idea/.name
+++ b/CustomerService/.idea/.name
@@ -1 +1 @@
...
...
...
3、标签签名
如果你有GPG私钥的话,你也可以用GPG来给你的标签签名。-s用私钥签名一个标签,-m指定说明文字
$ git tag -s <tagname> -m “说明文字”
例如:
$ git tag -s v1.0 -m“version 1.0”
签名采用PGP签名,因此,必须首先安装gpg(GnuPG),如果没有找到gpg,或者没有gpg密钥对,就会报错:
gpg: signing failed: secret key not available
error: gpg failed to sign the data
error: unable to sign the tag
然后,用命令git show <tagname>
可以看到PGP签名信息了。