当前位置: 首页 > news >正文

【Git】-- 标签管理

文章目录

  • 1. 标签管理
    • 1.1 标签的作用
    • 1.2 操作标签
    • 1.3 创建标签
    • 1.4 查看有哪些标签
    • 1.5 查看标签中存放的是什么
    • 1.6 给前面的提交打标签
    • 1.7 给标签添加描述
    • 1.8 删除标签
    • 1.3 推送标签
      • 1.3.1 单个标签推送
      • 1.3.2 多个标签推送
      • 1.3.3 删除标签并推送

更多Git相关知识: Git专栏

1. 标签管理

1.1 标签的作用

标签tag,可以简单的理解为是对某次commit 的一个标识,相当于起了一个别名。例如,在项目发布某个版本的时候,针对最后一次commit 起一个v1.0 这样的标签来标识里程碑的意义。

这有什么用呢?相较于难以记住的 commit id,tag 很好的解决这个问题,因为 tag 一定要给一个让人容易记住,且有意义的名字。当我们需要回退到某个重要版本时,直接使用标签就能很快定位到。

1.2 操作标签

打标签是针对提交打的标签。

1.3 创建标签

该操作会默认给我们最新的依次提交打上v1.0的标签。

root@VM-0-3-ubuntu:~/remote-gitcode# git tag v1.0

1.4 查看有哪些标签

root@VM-0-3-ubuntu:~/remote-gitcode# git tagv1.0

或者

root@VM-0-3-ubuntu:~/remote-gitcode# tree .git.git ├── branches ├── COMMIT_EDITMSG ├── config ├── description ├── FETCH_HEAD ├── HEAD ├── hooks │ ├── applypatch-msg.sample │ ├── commit-msg.sample │ ├── fsmonitor-watchman.sample │ ├── post-update.sample │ ├── pre-applypatch.sample │ ├── pre-commit.sample │ ├── pre-merge-commit.sample │ ├── prepare-commit-msg.sample │ ├── pre-push.sample │ ├── pre-rebase.sample │ ├── pre-receive.sample │ ├── push-to-checkout.sample │ ├── sendemail-validate.sample │ └── update.sample ├── index ├── info │ └── exclude ├── logs │ ├── HEAD │ └── refs │ ├── heads │ │ └── master │ └── remotes │ └── origin │ ├── HEAD │ ├── master │ └── mater ├── objects │ ├── 05 │ │ └── fe86c3cd7ec2287a059a43b68cdc45f79cc43b │ ├── 09 │ │ └── 9c367d45aa723611f3721038110dc2c7a9eecf │ ├──13│ │ └── b46fa6ad76bb659f965fd48c86ed49842aecc3 │ ├──30│ │ └── 0659b8f65f8f6ca9160b7154a62c06359772f8 │ ├── 3f │ │ └── 14f45e2fbcd94d370f0a2b0d1ef194ac8c69c5 │ ├──45│ │ └── 23b2b9da80d0b335e1652f6070b4de1568b906 │ ├── 4b │ │ └── c8161e604f7e008eacccfdcae36171e119d1e9 │ ├── 8d │ │ └── 0e41234f24b6da002d962a26c2495ea16a425f │ ├── a5 │ │ └── 421d46e76e71c849d56ef0dfd2c64433a2e553 │ ├── f4 │ │ └── 179bfa0f591af2b60a933413a0fd0499dc3ba1 │ ├── info │ └── pack │ ├── pack-c20b9d41255e962915ba1d4372cfe6478f7ec66e.idx │ ├── pack-c20b9d41255e962915ba1d4372cfe6478f7ec66e.pack │ └── pack-c20b9d41255e962915ba1d4372cfe6478f7ec66e.rev ├── ORIG_HEAD ├── packed-refs └── refs ├── heads │ └── master ├── remotes │ └── origin │ ├── HEAD │ ├── master │ └── mater └── tags └── v1.0

1.5 查看标签中存放的是什么

root@VM-0-3-ubuntu:~/remote-gitcode# cat .git/refs/tags/v1.0099c367d45aa723611f3721038110dc2c7a9eecf

查看提交日志:

root@VM-0-3-ubuntu:~/remote-gitcode# git logcommit 099c367d45aa723611f3721038110dc2c7a9eecf(HEAD ->master, tag: v1.0, origin/master, origin/HEAD)Author: pepper-cloth<1186710125@qq.com>Date: Mon Jan1213:34:232026+0800add.git ignore commit 300659b8f65f8f6ca9160b7154a62c06359772f8 Author: cuckoo<1186710125@qq.com>Date: Mon Jan1205:14:432026+0000 update file.txt. Signed-off-by: cuckoo<1186710125@qq.com>.......

可以看到,v1.0标签里卖弄存放的就是最后一次提交的commit id。

1.6 给前面的提交打标签

给前面的提交打标签,需要拿到前面提交的commit id。

获取前面提交的commit id:

root@VM-0-3-ubuntu:~/remote-gitcode# git log --pretty=oneline --abbrev-commit099c367(HEAD ->master, tag: v1.0, origin/master, origin/HEAD)add.git ignore 300659b update file.txt. f4179bf(origin/mater)addfile.txt f59a47a Initial commit

打标签:

root@VM-0-3-ubuntu:~/remote-gitcode# git tag v0.9 300659broot@VM-0-3-ubuntu:~/remote-gitcode# git tagv0.9 v1.0

1.7 给标签添加描述

root@VM-0-3-ubuntu:~/remote-gitcode# git tag -a v0.8 -m "important tag: xxx" f4179bfroot@VM-0-3-ubuntu:~/remote-gitcode# git tagv0.8 v0.9 v1.0 root@VM-0-3-ubuntu:~/remote-gitcode# git show v0.8tag v0.8 Tagger: pepper-cloth<1186710125@qq.com>Date: Mon Jan1220:35:092026+0800 important tag: xxx commit f4179bfa0f591af2b60a933413a0fd0499dc3ba1(tag: v0.8, origin/mater)Author: pepper-cloth<1186710125@qq.com>Date: Mon Jan1213:05:242026+0800addfile.txtdiff--gita/file.txt b/file.txt newfilemode100644index 0000000..8d0e412 --- /dev/null +++ b/file.txt @@ -0,0 +1 @@ +hellogit

1.8 删除标签

root@VM-0-3-ubuntu:~/remote-gitcode# git tag -d v0.9Deleted tag'v0.9'(was 300659b)root@VM-0-3-ubuntu:~/remote-gitcode# git tagv0.8 v1.0

1.3 推送标签

1.3.1 单个标签推送

root@VM-0-3-ubuntu:~/remote-gitcode# git push origin v1.0Total0(delta0), reused0(delta0), pack-reused0remote: Powered by GITEE.COM[1.1.23]remote: Set trace flag f3477ba6 To gitee.com:pepper-cloth/remote-gitcode.git *[new tag]v1.0 ->v1.0

1.3.2 多个标签推送

root@VM-0-3-ubuntu:~/remote-gitcode# git push origin --tagsEnumerating objects:1, done. Counting objects:100%(1/1), done. Writing objects:100%(1/1),166bytes|166.00KiB/s, done. Total1(delta0), reused0(delta0), pack-reused0remote: Powered by GITEE.COM[1.1.23]remote: Set trace flag 9440c2a3 To gitee.com:pepper-cloth/remote-gitcode.git *[new tag]v0.8 ->v0.8

1.3.3 删除标签并推送

root@VM-0-3-ubuntu:~/remote-gitcode# git push origin :v1.0remote: Powered by GITEE.COM[1.1.23]remote: Set trace flag ac4ae0a3 To gitee.com:pepper-cloth/remote-gitcode.git -[deleted]v1.0 root@VM-0-3-ubuntu:~/remote-gitcode# git tagv0.8
http://www.zskr.cn/news/1459418.html

相关文章:

  • 2026 泾县黄金回收靠谱商家推荐|铂金白银 K 金金条首饰回收价格与门店指南 - 同城好物推荐官
  • BetterJoy终极指南:如何让Switch控制器在PC上完美工作
  • TMS320F28P550SJ9学习笔记18:C2000Ware软件包导出一份empty工程
  • 逛遍杭州才明白:靠谱伴手礼不用贵,非遗杨先生糕点成出行标配 - 玖叁鹿
  • 新式杭州伴手礼出圈:摒弃老牌礼品定式,非遗杨先生糕点承包出行心意 - 玖叁鹿
  • 同态加密(Homomorphic Encryption, HE)
  • GreedyCoreset采样技术:PatchCore内存库压缩5.1倍的核心原理
  • GPT-4 Turbo与DALL-E 3实战能力深度解析
  • 终极宝可梦存档管理解决方案:PKSM完整使用指南
  • QGIS制图进阶:除了四色定理,你的行政区划图配色还能玩出哪些花样?(附样式文件)
  • 别再手动配角色了!用PFCG批量分配Fiori磁贴权限(以Manage Banks为例)
  • 告别重复劳动:用快马平台的ai能力生成高效开发工具函数
  • MATLAB图像缺陷检测入门实战包:含12张实拍样图、带注释代码与坐标标注表
  • Python vs MATLAB:手把手教你实现信号波形特征提取(附完整代码与避坑指南)
  • 微软拼音中 通过注册表快速添加小鹤双拼
  • 别再只盯着M.2了!工控机里那个‘小插槽’MiniPCIe,到底能接多少种宝贝?
  • 别再只会录屏了!用FFmpeg的gdigrab和x11grab,5分钟搞定Windows/Linux桌面精准捕获
  • 从 Volatile 到 ThreadLocal:Java 线程安全机制备忘
  • 到访杭州伴手礼怎么选?老牌非遗杨先生糕点,把江南风土装进礼盒 - 玖叁鹿
  • KUKA KRC4/VKRC4/KR C5机器人ProfiNet通信用GSDML文件合集(2012–2022全版本)
  • 新疆旅拍摄影专属向导!懂拍照、会取景,定格新疆绝美风光 - 纯玩旅游分享
  • MySQL-主从/集群架构
  • 破解苏州平江路观前街核心商圈亲子住宿痛点:4D家庭住宿优化方法论如何打造高性价比四口之家住宿解决方案? - 速递信息
  • 2026 南京钻石回收平台星级排名测评:六家正规机构横向对比,添价收领跑全城 - 薛定谔的梨花猫
  • 面试官追问‘背靠背’场景?一个动画图解帮你彻底搞懂异步FIFO最坏情况分析
  • 百度网盘下载解析终极指南:告别限速,轻松获取真实下载地址
  • 别再只复现了!用PHPStudy+phpMyAdmin 4.8.1实战演练文件包含漏洞(从环境搭建到GetShell)
  • TAITherm 推出AI 助手功能
  • 地推团队必备干货,现卡开卡高佣平台优势拆解 - 资讯焦点
  • 2026天津黄金回收好去处,中检认证门店,足称实价告别压价套路 - 奢侈品回收评测