1). 在local端新增tag,如果commit_id为空,默认以最新的commit_id为准
$ git tag -a [tag_name] [commit_id]
$ git tag -a 1.0.1 -m '.' # 创建带附注的附注标签,m参数可选
2). 切换标签
$ git checkout 1.0.1 #跳转到某标签
$ git show 1.0.1 #查看标签版本信息
这块需要注意一下,使用checkout切换到某标签时,git会提示你处于一个空分支,需要使用-b来创建一个分支,以便进行分支管理。
$ git tag -a tag_temp a8a7d63d887bc65c23d0407c2569dc2f796b06a8 # 在某个commit_id上创建tag,写注释
$ git tag # 查看tag
$ git checkout tag_temp # 切换到指定tag,git会提示你如下
Note: checking out 'tag_temp'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at a8a7d63... xxxxx
$ git checkout -b temppp # 在tag到临时分支上创建本地分支
或者直接根据tag创建分支
$ git checkout -b bugfix-tempp tag_temp
3). 在remote端新增tag
$ git push origin [tag_name]
$ git push origin --tag # 一次將所有tag push上去
4). 在local端刪除tag
$ git tag -d [tag_name]
5). 在remote端刪除tag
$ git push origin :refs/tags/[tag_name]