Git标签管理
Posted 玉曲风
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git标签管理相关的知识,希望对你有一定的参考价值。
发布一个版本时,我们通常会在版本库中打上一个标签,这样,就唯一确定了打标签时刻的版本了,将来无论什么时候,取某个标签的版本,就是
把那个打标签的时刻的历史版本取出来,所以,标签也是版本库的一个快照,Git的标签虽然是版本库的快照,但其实它就是指向某个commit的指针
(跟分支很像,但是分支可以移动,标签不能移动),所以创建和删除一个标签都是在一瞬间完成的。
在Git中打标签非常简单,首先切换到需要打标签的分支上:
输入git tag name 就可以打一个新的标签:
$ git tag v1.0
可以用命令git tag 查看所有的标签:
$ git tag
v1.0
默认标签是打在最新提交的commit上的。有时候,如果忘记打标签,那怎么办?
方法就是找到历史提交的commit id ,然后打上就可以了
$ git log --pretty=oneline --abbrev-commit
dbfc0ee merge bug fix 119
b4d16ef bug 119 had fix
8e64728 merge with no-ff
4f4f23a dev commit
f3d8f1e branch merge
4bb4c5a master branch merge test
cccee34 newbranch first commit
0d0bbca dev first commit
d5aea29 master first commit
023ee21 Initial commit
比如要对“branch merge”这次提交打上标签,它对应的commit id是"f3d8f1e",敲入命令:
$ git tag v0.9 f3d8f1e
查看下所有的标签:
[email protected] MINGW32 /c/gitskill (master)
$ git tag
v0.9
v1.0
注意:标签不是按照时间顺序列出的,而是按照字母的顺序列出的,可以用git show tagname查看标签信息:
$ git show v1.0
commit dbfc0eebcb89072cf76cdda1eccea37c8b22db73
Merge: 8e64728 b4d16ef
Author: mars <[email protected]>
Date: Tue May 24 18:04:26 2016 +0800
merge bug fix 119
还可以创建带有说明的标签,用-a指定标签名,-m指定说明文字:
[email protected] MINGW32 /c/gitskill (master)
$ git tag -a v0.1 -m "version 0.1 released" cccee34
[email protected] MINGW32 /c/gitskill (master)
$ git tag
v0.1
v0.9
v1.0
[email protected] MINGW32 /c/gitskill (master)
$ git show v0.1
tag v0.1
Tagger: mars <[email protected]>
Date: Tue May 24 22:37:10 2016 +0800
version 0.1 released
commit cccee3487123b38970e76b95c43269661248c528
Author: mars <[email protected]>
Date: Tue May 24 15:40:12 2016 +0800
newbranch first commit
还可以通过-s用私钥签名一个标签:
$ git tag -s v0.2 -m "signed version 0.2 released" 8e64728
签名采用PGP签名,因此,必须首先安装gpg(GnuPG),如果没有找到gpg,或者没有gpg秘钥对,就会报错:
[email protected] MINGW32 /c/gitskill (master)
$ git tag -s v0.2 -m "signed version 0.2 released" 8e64728
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/documentation/faqs.html for more information
gpg: directory `/c/Users/LV/.gnupg‘ created
gpg: new configuration file `/c/Users/LV/.gnupg/gpg.conf‘ created
gpg: WARNING: options in `/c/Users/LV/.gnupg/gpg.conf‘ are not yet active during this run
gpg: keyring `/c/Users/LV/.gnupg/secring.gpg‘ created
gpg: keyring `/c/Users/LV/.gnupg/pubring.gpg‘ created
gpg: skipped "mars <[email protected]>": secret key not available
gpg: signing failed: secret key not available
error: gpg failed to sign the data
error: unable to sign the tag
生成GPG Key
gpg --gen-key 按提示自己生成
生成签名标签:
$ git tag -u "Mars Lv" -s v0.2 -m "signed version 0.2 released" 8e64728
生成后的签名标签:
$ git show v0.2
tag v0.2
Tagger: mars <[email protected]>
Date: Tue May 24 23:40:01 2016 +0800
signed version 0.2 released
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAABAgAGBQJXRHXRAAoJEKqD3K/XnFBf/4wP/jy7oclw+74r5VsUTVJydoiT
T9URpqOMTE/S3GokphhXo6eNpY8HC1Yd3keyXSU10U74QdkwH92f62ZAlSZOOWVw
MbjkXGlk6sQdsiFCnihsnRtbxDg0PYf5nDtJFCIZXtmZOeJ/43UudzKxL+23nNLM
qfdoOpenYZoTUaGWSMxJTYRKIVICoD8awB5R1AA71Dysv7yEfaGZKk1cHX4Bu3Tj
a+kpRx6D0WWZLz4pj6NRvtVyeGtbWACtJJy/Rr3RhmhognlOxDAZecdJ3Jxs1qAt
tKOGiKp1xWsEwRCTnanArMPf5NAjvIMzgG8roV2NvRXPu26lknM1fb9Yb4/SNeE1
cLAvRj1PxzDIwQEEZdb0og3hPtrfaAEqwM8re70iB9iEI/1IyrV4L+/7Lp9ebONO
qNIuSHMxropkxAaQzgknWEVmSDWfydmY8M5oD8NGMMZOZpqhtfeGORP+5SRWkyg7
AoZSivx1wvzUH+2CzOjchf7Z+ZBqynNkB+CZxo1gtLOnrNkiiMnVlUIRYvRObgog
ExHvcAWBR9gajSHQDFNkvL8kJYkw6M5Rjg1Je6R+GZqfyrV/krKMjs+P74cuUCi0
D/b51gE48ZBu6lD8VKY5mw0jGlWM67A+n79OwFMNTK+f4eP+rUXYIXa2pDFE1zbj
oU7mTnHEkNUVQIeuyVLo
=4Ml3
[email protected] MINGW32 /c/gitskill (master)
$ git tag -v v0.2
object 8e647284624ec4ae666bebcdce784aa5db8d39d6
type commit
tag v0.2
tagger mars <[email protected]> 1464104401 +0800
signed version 0.2 released
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/documentation/faqs.html for more information
gpg: Signature made 2016年05月24日 23:40:01 using RSA key ID D79C505F
gpg: Good signature from ""Mars Lv" (GPG key for Mars) <[email protected]>"
-u, --local-user <key-id> 使用另一个Key签名此tag,“Mars Lv”是我生成的key-id
以上是关于Git标签管理的主要内容,如果未能解决你的问题,请参考以下文章
GitGit 分支管理 ( 克隆远程分支 | 克隆 master 分支 git clone | 查看远程分支 git branch -a | 克隆远程分支 git checkout -b )(代码片段
GitGit 分支管理 ( 克隆远程分支 | 克隆 master 分支 git clone | 查看远程分支 git branch -a | 克隆远程分支 git checkout -b )(代码片段