git 打标签

git 打标签

1. 显示已有标签

$ git tag 
v0.11.5
v0.11.5.sp1
v0.12.0
v0.12.sp1
v0.13
v0.14.0
v0.14.1

-l 显示指定标签

$ git tag -l 'v0.11.*'
v0.11.5
v0.11.5.sp1

2. 新建标签

Git 使用的标签有两种类型:轻量级的(lightweight)和含附注的(annotated)。轻量
级标签就像是个不会变化的分支,实际上它就是个指向特定提交对象的引用。而含附注标
签,实际上是存储在仓库中的一个独立对象,它有自身的校验和信息,包含着标签的名字,
电子邮件地址和日期,以及标签说明

-a 创建annotated标签,-m 选项则指定了对应的标签说明

Administrator@6XIGRIJ0JJDRMSP MINGW64 /e/guotengfei/git/RAP (release)
$ git tag -a v0.15.0 -m 'my 0.15.0'

Administrator@6XIGRIJ0JJDRMSP MINGW64 /e/guotengfei/git/RAP (release)
$ git tag
v0.11.5
v0.11.5.sp1
v0.12.0
v0.12.sp1
v0.13
v0.14.0
v0.14.1
v0.15.0

git show 命令查看相应标签的版本信息,并连同显示打标签时的提交对象。

$ git show v0.15.0
tag v0.15.0
Tagger: guotengfei <guotengfei@zzvcom.com>
Date:   Sat Feb 3 15:38:17 2018 +0800

my 0.15.0

commit e45a5fe0e53806369ed7d8a4b5dd373c3e663414 (HEAD -> release, tag: v0.15.0, origin/release, origin/HEAD)
Merge: 2fdd4f79 61afa50c
Author: 墨智 <mozhi.gyy@alibaba-inc.com>
Date:   Tue Nov 22 10:39:32 2016 +0800

    Merge branch 'master' into release

git tag默认创建lightweight标签

Administrator@6XIGRIJ0JJDRMSP MINGW64 /e/guotengfei/git/RAP (release)
$ git tag v0.16.0

Administrator@6XIGRIJ0JJDRMSP MINGW64 /e/guotengfei/git/RAP (release)
$ git show v0.16.0
commit e45a5fe0e53806369ed7d8a4b5dd373c3e663414 (HEAD -> release, tag: v0.16.0, tag: v0.15.0, origin/release, origin/HEAD)
Merge: 2fdd4f79 61afa50c
Author: 墨智 <mozhi.gyy@alibaba-inc.com>
Date:   Tue Nov 22 10:39:32 2016 +0800

    Merge branch 'master' into release

3. 签署标签

如果你有自己的私钥,还可以用 GPG 来签署标签,只需要把之前的 -a 改为 -s (译注:取 Signed 的首字母)即可。

$ git tag -s v0.17.0 -m 'my signed tag'
gpg: directory `/c/Users/Administrator/.gnupg' created
gpg: new configuration file `/c/Users/Administrator/.gnupg/gpg.conf' created
gpg: WARNING: options in `/c/Users/Administrator/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/c/Users/Administrator/.gnupg/secring.gpg' created
gpg: keyring `/c/Users/Administrator/.gnupg/pubring.gpg' created
gpg: skipped "guotengfei <guotengfei@zzvcom.com>": secret key not available
gpg: signing failed: secret key not available
error: gpg failed to sign the data
error: unable to sign the tag

失败了,哎,没私钥。
git tag -v [tag-name] (译注:取 verify 的首字母)的方式验证已经签署的标签


4. 后期加标签

Administrator@6XIGRIJ0JJDRMSP MINGW64 /e/guotengfei/git/RAP (release)
$ git log -3
commit e45a5fe0e53806369ed7d8a4b5dd373c3e663414 (HEAD -> release, tag: v0.16.0, tag: v0.15.0, origin/release, origin/HEAD)
Merge: 2fdd4f79 61afa50c
Author: 墨智 <mozhi.gyy@alibaba-inc.com>
Date:   Tue Nov 22 10:39:32 2016 +0800

    Merge branch 'master' into release

commit 2fdd4f798bc2e29a49d4f88c6eef1243b34f1990
Author: 墨智 <mozhi.gyy@alibaba-inc.com>
Date:   Mon Nov 21 11:03:34 2016 +0800

    更新阿里云广告

commit 61afa50c5dc23980e304a9b7cf935f562fbc45be (origin/v0.14.12, origin/master)
Author: 墨智 <mozhi.gyy@alibaba-inc.com>
Date:   Mon Nov 21 10:58:28 2016 +0800

    fix #746

Administrator@6XIGRIJ0JJDRMSP MINGW64 /e/guotengfei/git/RAP (release)
$ git tag -a v0.18.0 2fdd4f798

Administrator@6XIGRIJ0JJDRMSP MINGW64 /e/guotengfei/git/RAP (release)
$ git tag -l v0.18.0
v0.18.0

5. 分享标签

默认情况下,git push 并不会把标签传送到远端服务器上,只有通过显式命令才能分享标签到远端仓库。其命令格式如同推送分支,运行 git push origin [tagname] 即可。
如果要一次推送所有(本地新增的)标签上去,可以使用 –tags 选项

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值