一个git仓库中会有N多commit,对于某些特殊commit我们会需要打上tag进行标记,方便后续管理。比如对于用来做release的master分支基本每次都会打上一个tag,另外对于其他某些commit具有某些特殊性我们也会打上tag进行标记。如下图中vA0.0.2和vB0.0.2
Tag基本操作
git tag <lightTagName> | 创建轻量标签 轻量标签其只是一个像某commit的引用 不存储名称时间戳及标签说明等信息。 |
git tag -a <tagName> -m <comment> | 创建带附注标签 相对于轻量标签,附注标签是一个独立的标签对象, 包含了名称时间戳以及标签备注等信息, 同时指向对应的commit。定义方法如下 |
git tag -a <tagName> <SHA> -m <comment> | 像特定的commit添加标签 使用该commit对应的SHA值即可 |
git push origin --tags | 推送所有标签 |
git push origin <tagName> | 推送指定版本的标签 |
git tag | 列出查看所有tag |
git show <tagName> | 查看某个tag详情 |
git checkout <tagName> | checkout到某个tag指向的commit 但checkout后处于游离状态 |
git tag -d <tagName> | 删除某个标签 |
git tag | xargs -I {} git tag -d {} | 批量删除本地tag |
git tag | xargs -I {} git push origin :refs/tags/{} | 批量删除远程tag |