git 的 tag 分为两种类型:
- Lightweight Tags
- Annotated Tags
Lightweight Tags
只是保存了一个指向某次 commit 的指针。使用 git show 命令查看只有最后一次 commit 的记录信息。
$ git show v1.4-lw
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version number
Annotated Tags
包含完整的全部提交记录,包含创建 tag 人的信息(用户名,邮件等),创建 tag 的时间,还有备注信息。
$ git show v1.4
tag v1.4
Tagger: Ben Straub <ben@straub.cc>
Date: Sat May 3 20:19:12 2014 -0700
my version 1.4
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version number
如何创建 tag
创建 lightweight tag 直接用
git tag v1.4 # v1.4 可以替换为自己制定的版本
创建 annotated tag:
git tag -a v1.4 -m "my version 1.4" # 多了一个 -a 参数
要是写成:
git tag v1.4 -m "my version 1.4"
虽然没有 -a 但是因为有 -m 也会隐式的创建 annotated tag。
push tag 到远程 repo 中
默认情况下 git push 不会把 tag push 到远程 repo 中,所以需要手动提交
git push origin v1.4
要是需要一次 push 全部的 tag 到远程的 repo 可以
git push origin --tags
checkout 某个 tag
$ git checkout -b version2 v2.0.0
Switched to a new branch 'version2'
删除 tag
$ git tag -d release01
$ git push origin :refs/tags/release01
参考:
https://git-scm.com/book/en/v2/Git-Basics-Tagging
https://confluence.atlassian.com/bitbucket/how-do-i-remove-or-delete-a-tag-from-a-git-repo-282175551.html