对于一般的业务后端系统来说, git tag 命令是不怎么会被用到的;
但是对于一个库的开发者来说, git tag 命令很重要, 每一个正式版本 / 里程碑的发布, 都需要用 git tag 来标记, 方便日后追溯, 问题排查;
创建与删除 tag
注意: git tag 无法修改, 只能先删除再重新创建;1
2
3
4
5
6
7
8
9# 在当前分支 HEAD commit 创建普通 tag
git tag tag_name
# 创建附带 message 的标签(-a: annotated)
git tag -a tag_name -m "commit message ..."
# 在给定的 commit 上创建 tag
git tag -a tag_name -m "commit message ..." commit_number
# 删除 tag
git tag -d tag_name
查看与搜索 tag
1 | # 列出当前仓库的所有 tags |
将 tag 推送到远程仓库
如若不指定, git push 命令不会主动将 tags 推送到远程仓库;
指定方式如下:1
2
3
4# 推送指定 tag 至远程仓库
git push [remote_repo_name] tag_name
# 推送所有 tags 至指定仓库
git push [remote_repo_name] --tags