Skip to content

tag

git tag 用于在 Git 中创建标签,通常用于给特定的提交打上标记,比如发布版本。以下是 git tag 的基本用法:

创建一个轻量标签(Lightweight Tag)

轻量标签只是一个提交的引用,用法简单直接:

bash
git tag 标签名

例如:

bash
git tag v1.0

创建带注释的标签(Annotated Tag)

带注释的标签可以包含附加信息,比如作者、日期、描述等,更适合用于发布版本。

bash
git tag -a 标签名 -m "标签描述"

例如:

bash
git tag -a v1.0 -m "发布第一个版本"

查看所有标签

查看项目中的所有标签:

bash
git tag

查看标签详细信息

查看特定标签的详细信息(适用于带注释的标签):

bash
git show 标签名

例如:

bash
git show v1.0

给某个特定提交打标签

如果想给以前的某个提交打标签,可以在标签命令后面指定提交的哈希值:

bash
git tag -a 标签名 提交哈希 -m "标签描述"

例如:

bash
git tag -a v0.9 abc123 -m "这是测试版"

删除标签

本地删除某个标签:

bash
git tag -d 标签名

例如:

bash
git tag -d v1.0

推送标签到远程仓库

默认情况下,git push 不会推送标签,需要手动指定:

bash
# 推送单个标签
git push origin v1.0

# 推送所有标签
git push origin --tags

删除远程标签

删除远程仓库中的标签,可以使用以下命令:

bash
git push origin --delete 标签名

例如:

bash
git push origin --delete v1.0

切换到标签

bash
git checkout v1.0

基于 MIT 许可发布