【Git】Git tag

标签

针对某一时间点的版本做标记
常用于版本发布

列出标签
  • git tag
  • git tag -l ‘tag name’,搜索符合模式的标签
打标签
  • git标签分为两种类型
  • 轻量标签:指向提交对象的引用
  • 附注标签:独立的对象(建议采用)
# 创建轻量标签
git tag dailyRelease
# 创建附注标签
git tag -a dailyRelease-m "dailyRelease"
切换到标签
git checkout dailyRelease
  • 查看标签的版本信息
git show dailyRelease
删除标签
  • 删除本地标签
git tag -d dailyRelease

-删除远程标签

# 删除远程标签,相当于推送一个空的标签,到目标便签
# git push origin refs/tags/源标签: refs/tags/目标标签
git push origin :refs/tags/dailyRelease
给指定的commit打标签
git tag -a dailyRelease commitID
标签发布
# 该命令相当于
# git push origin refs/tags/dailyRelease: refs/tags/dailyRelease
# 将v0.0.1标签提交到服务器
git push origin dailyRelease

# 将本地所有标签一次性提交到git服务器
git push origin -tags
查看标签操作
git tag
# 指向指定的标签记录的代码状态
# 但会处于一个空的分支上
git checkout xxxx
Git系列
07-19
### 查看 Git 标签 要查看 Git 仓库中的标签,可以使用以下命令: ```bash git tag ``` 该命令会列出仓库中的所有标签名称。如果需要查看标签的详细信息(例如附注信息、创建者、创建时间等),可以使用: ```bash git show <tag_name> ``` 例如: ```bash git show v1.0.2 ``` 此命令会显示标签 `v1.0.2` 的详细信息,包括标签附注和对应的提交信息 [^2]。 --- ### 创建 Git 标签 Git 支持两种类型的标签:**轻量级标签**和**附注标签**。 - **创建轻量级标签**: ```bash git tag v1.0.1 ``` 轻量级标签只是一个简单的指针,指向某个提交,没有额外的信息 [^2]。 - **创建附注标签**: ```bash git tag -a v1.0.2 -m "release version" ``` 附注标签包含更多信息,例如标签创建者、时间戳和描述信息,适合用于正式发布的版本 [^2]。 如果希望在某个特定的提交上打标签,可以指定提交的 `commit id`: ```bash git tag <tag_name> <commit_id> ``` 例如: ```bash git tag v1.0.3 abc1234 ``` 该命令会在 `abc1234` 提交上创建标签 `v1.0.3` [^4]。 --- ### 删除 Git 标签 删除本地标签的命令如下: ```bash git tag -d <tag_name> ``` 例如: ```bash git tag -d v1.0.1 ``` 如果需要删除远程仓库的标签,可以使用以下命令: ```bash git push origin :refs/tags/<tag_name> ``` 或者更简洁的命令: ```bash git push origin --delete tag <tag_name> ``` 例如: ```bash git push origin --delete tag v1.0.1 ``` 删除远程标签后,本地标签不会自动删除,如需同步删除,需手动执行 `git tag -d` 命令 [^2]。 --- ### 推送 Git 标签到远程仓库 将本地标签推送到远程仓库,可以使用以下命令: - **推送单个标签**: ```bash git push origin <tag_name> ``` 例如: ```bash git push origin v1.0.2 ``` - **推送所有标签**: ```bash git push origin --tags ``` 该命令会将本地所有的标签一次性推送到远程仓库 [^2]。 --- ### 从远程仓库拉取 Git 标签 当其他开发者推送了新的标签到远程仓库时,可以通过以下命令拉取标签: ```bash git pull ``` 默认情况下,`git pull` 会自动获取远程标签。如果需要显式获取标签,可以使用: ```bash git fetch --tags ``` 该命令会获取远程仓库的所有标签并更新本地标签 [^2]。 --- ### 检出 Git 标签 检出标签可以基于标签创建一个新的分支,命令如下: ```bash git checkout -b <branch_name> <tag_name> ``` 例如: ```bash git checkout -b myfeature v1.0.2 ``` 该命令会基于标签 `v1.0.2` 创建一个名为 `myfeature` 的本地分支。之后可以将该分支推送到远程仓库: ```bash git push -u origin myfeature ``` 该分支为本地分支,需要手动推送至远程 [^2]。 --- ### 总结 Git 标签是版本管理中非常重要的工具,可以用于标记特定版本,便于后续查找和回溯。通过 `git tag` 可以查看、创建、删除标签,通过 `git push` 和 `git pull` 可以管理远程标签,而 `git checkout` 则可以基于标签创建分支。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林多

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值