列出标签
git tag
git tag -l 'pattern'
$ git tag -l 'v1.8.5*'v1.8.5v1.8.5-rc0v1.8.5-rc1v1.8.5-rc2v1.8.5-rc3v1.8.5.1v1.8.5.2v1.8.5.3v1.8.5.4v1.8.5.5
创建标签
git有两种标签:轻量标签、附注标签
- 轻量标签:只是一个特定提交的引用
git tag <tagname>:创建轻量标签,只需要提供标签名字
$ git tag v1.4-lw$ git tagv0.1v1.3v1.4v1.4-lwv1.5
- 附注标签:是存储在数据库中的一个完整对象,是可以被校验的
git tag -a <tagname> -m 'something'
$ git tag -a v1.4 -m 'my version 1.4'$ git tagv0.1v1.3v1.4
git show <tagname>:显示标签信息与对应的提交信息
$ git show v1.4
后期打标签
假设提交历史是这样的:
$ git log --pretty=oneline15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment'a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support0d52aaab4479697da7686c15f77a3d64d9165190 one more thing6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment'0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function4682c3261057305bdd616e23b64b0857d832627b added a todo file166ae0c4d3f420721acbb115cc33848dfcc2121a started write support9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
想在 “updated rakefile”打上tag 'v1.2'
$ git tag -a v1.2 9fceb02
共享标签
创建完标签,必须推送到共享服务器上,就像共享远程分支一样
git push [remote-name] [tagname]
git push origin v1.5:推送tag v1.5到远程服务端
git push origin --tags:所有不在远程仓库的tag都传送过去
检出标签
git checkout -b [branchname] [tagname]:在特定的标签上创建一个新分支
$ git checkout -b version2 v2.0.0Switched to a new branch 'version2'
参考文献:https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE