$ git tag -a v1.4 -m ‘version 1.4′
$ git tag
v0.1
v1.3
v1.4
‘-m’指明标签信息,跟标签一起存储。如果你不使用-m指明标签信息,git会自动启动文本编辑器让你输入。
可以使用 git show 命令查看相应标签的版本信息,并连同显示打标签时的提交对象。
$ git show v1.4
tag v1.4
Tagger: Scott Chacon
Date: Mon Feb 9 14:45:11 2009 -0800
my version 1.4
commit 15027957951b64cf874c3557a0f3547bd83b3ff6
Merge: 4a447f7… a6b4c97…
Author: Scott Chacon
Date: Sun Feb 8 19:02:46 2009 -0800
Merge branch ‘experiment’
现在,如果有人克隆或者在线同步你的git仓库的话,标签也会一并同步了。 实战:
$ git checkout v0.11.2
Note: checking out 'v0.11.2'.
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 adadaab... v0.11.2
$ git branch
* (detached from v0.11.2)
chucklu_master
chucklu_zhCN
master
test
2016年11月01日更新 Tag和Commit
https://github.com/chucklu/tools 从当前的commit往后查找
git tag --contains commit-id
$ git tag --contain d9df
1.0.0.0
1.0.0.1
1.0.0.2
1.0.0.3
1.0.0.4 从当前的commit往前查找
git describe --tags commit-id
$ git describe --tags 601f
1.0.0.0-2-g601fe8a
$ git describe --tags d493
1.0.0.0-3-gd493bdf
$ git describe --tags b627
1.0.0.0-1-gb627c33
$ git describe --tags 16ec
1.0.0.0
$ git describe --exact-match --tag 16ec
1.0.0.0