使用 Git tag
命令可以给 Git 库中的指定提交设置标记或转移已经存在的标签。
给某个提交设置标签:
git tag <tagname> <commit>
其中 <tagname>
为标签名称,<commit>
为提交的 SHA-1 校验和、commit ID 或者 branch 名称。
转移已经存在的标签:
git tag -f <tagname> <commit>
其中 -f
选项表示强制覆盖已有的标签,<tagname>
为标签名称,<commit>
为新的提交的 SHA-1 校验和、commit ID 或者 branch 名称。
查看已经存在的标签:
git tag
查看某个标签所指向的提交:
git show <tagname>
需要注意的是,标签默认是不会被推送到远程仓库的,需要使用 git push
命令的 --tags
选项或者直接指定标签名称来推送标签。
推送本地所有标签到远程仓库:
git push --tags
推送指定标签到远程仓库:
git push origin <tagname>
其中 origin
为远程仓库的名称,<tagname>
为标签名称。