标签管理
什么是标签?
发布一个版本时,我们通常先在版本库中打一个标签(tag),这样,就唯一确定了打标签时刻的版本。将来无论什么时候,取某个标签的版本,就是把那个打标签的时刻的历史版本取出来。所以,标签也类似版本库的一个快照。
Git的标签虽然类似版本库的快照,但其实它就是指向某个commit的指针(跟分支很像对不对?但是分支可以移动,标签不能移动),所以,创建和删除标签都是瞬间完成的。
tag
就是一个让人容易记住的有意义的名字,它跟某个commit绑在一起。
创建标签
注意: 我们一般打标签是为了发布一个东西,或指明一个阶段,往往会采取在主干上进行标签的标记,不排除在其他开发分支上进行其他小阶段型的标记。
git tag tagName
(master)
$ git tag V0.0.1
(master)
$ git tag
V0.0.1
默认标签是打在最新提交的commit
上的。
$ git show V0.0.1
commit 43813d7500501deaef3ec60467f0c87abdf42cd0 (HEAD -> master, tag: V0.0.1, origin/feature4)
Merge: 80d7c40 256bf29
Author: ys-yangsong <482109583@qq.com>
Date: Tue Dec 10 15:49:01 2019 +0800
从dev合并到master 2019年12月10日15:48:53
有时候,如果忘了打标签,比如,现在已经是周五了,但应该在周一打的标签没有打,怎么办?
方法是找到历史提交的commit id
,然后打上就可以了:
git tag tagName commitId
可以对指定的commitId进行标签标记!
可以对标签进行描述
git tag -a tagName -m "xxxxxxxxx" commitId
git show <tagName>
是可以看到标签的描述信息的
PGP签名标签:
$ git tag -s <tagname> -m <description> <branchname> or commit_id
git tag -s <tagname> -m "blablabla..."
可以用PGP签名标签。
$ git tag -s V0.0.3 -m "标签0.0.3"
gpg: directory '/c/Users/Administrator/.gnupg' created
gpg: keybox '/c/Users/Administrator/.gnupg/pubring.kbx' created
gpg: skipped "ys-yangsong <482109583@qq.com>": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
error: unable to sign the tag
# 我的签名出错,是因为我的secret生成公钥时,没有指定密码,空密码生成自己的公钥的
标签是指向commit的死指针,分支是指向commit的活指针!!
仔细想下,这句话要怎么理解?
我们在dev分支打的标签,切换到master分支也是有可能会看到的,因为这个commitId有可能是两个分支都有的。
查看所有标签
$ git tag
推送一个本地标签
$ git push origin <tagname>
推送全部未推送过的本地标签
$ git push origin --tags
删除一个本地标签
$ git tag -d <tagname>
删除一个远程标签<本地标签另行删除>
$ git push origin :refs/tags/<tagname>
可以在GitHub上查看推送上去的标签