git tag标签管理
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
目录
一.为已经提交的版本打tag
1.标签管理概述
虽然每次commit都会生成一个commit id,但此方式无疑是不方便标记和记忆的。
git标签就是对指定的commit的一次快照,相当于commit ID起了一个容易记忆的名称,可以作为进度的里程碑标记。
git tag便于后续将特定时期的代码快速取出。
在代码发布时可以使用标签发布。
2.查看现有已经提交的commit ID
[root@prometheus-server31 devops]# git reflog
932ec59 (HEAD -> kafka, origin/kafka) HEAD@{0}: commit: add kafka
9e74e39 (origin/flink, flink) HEAD@{1}: checkout: moving from flink to kafka
9e74e39 (origin/flink, flink) HEAD@{2}: commit: add flink
b69638d (origin/master, master) HEAD@{3}: checkout: moving from master to flink
b69638d (origin/master, master) HEAD@{4}: merge docker: Merge made by the 'ort' strategy.
828e023 HEAD@{5}: merge k8s: Fast-forward
005b95d HEAD@{6}: checkout: moving from k8s to master
828e023 HEAD@{7}: commit: add k8s info
005b95d HEAD@{8}: checkout: moving from docker to k8s
5b1e29f HEAD@{9}: commit: add docker info
005b95d HEAD@{10}: checkout: moving from k8s to docker
005b95d HEAD@{11}: checkout: moving from master to k8s
005b95d HEAD@{12}: reset: moving to 005b95d
6eacc9c HEAD@{13}: commit: golang demo
005b95d HEAD@{14}: commit (initial): add go.mod
[root@prometheus-server31 devops]#
2.为已经提交的commit ID打标签
[root@prometheus-server31 devops]# git tag -a 'Kafka-v3.8.0' -m 'Kafka v3.8.0版本发布' # 若不指定commit ID则默认为最新的commit ID打标签。
[root@prometheus-server31 devops]#
[root@prometheus-server31 devops]# git tag -a 'Flink-v2.0' -m 'Flink v2.0版本发布' 9e74e39 # 为指定的commit ID打标签。
[root@prometheus-server31 devops]#
[root@prometheus-server31 devops]# git tag
Flink-v2.0
Kafka-v3.8.0
[root@prometheus-server31 devops]#
二.查看tag信息
1.查看现有的tag列表信息
[root@prometheus-server31 devops]# git tag
Flink-v2.0
Kafka-v3.8.0
[root@prometheus-server31 devops]#
2.查看某个tag的详细信息
[root@prometheus-server31 devops]# git show Flink-v2.0
tag Flink-v2.0
Tagger: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 23:04:12 2024 +0800
Flink v2.0版本发布
commit 9e74e39327f26b9d3d8dc241eb85b26413e37ed1 (tag: Flink-v2.0, origin/flink, flink)
Author: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 22:32:15 2024 +0800
add flink
diff --git a/flink.txt b/flink.txt
new file mode 100644
index 0000000..fa29c21
--- /dev/null
+++ b/flink.txt
@@ -0,0 +1 @@
+https://flink.apache.org/
[root@prometheus-server31 devops]#
3.查看commit ID并显式tag相关信息
[root@prometheus-server31 devops]# git log
commit 932ec59bbff547666f92aff82f691ac030d2fd86 (HEAD -> kafka, tag: Kafka-v3.8.0, origin/kafka)
Author: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 22:37:29 2024 +0800
add kafka
commit 9e74e39327f26b9d3d8dc241eb85b26413e37ed1 (tag: Flink-v2.0, origin/flink, flink)
Author: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 22:32:15 2024 +0800
add flink
commit b69638dee63a0fd9e631014c284aff5749d90960 (origin/master, master)
Merge: 828e023 5b1e29f
Author: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 22:11:58 2024 +0800
Merge branch 'docker'
commit 828e02325fb9d4a3b162c6743cc21507af290eae
Author: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 22:09:32 2024 +0800
add k8s info
commit 5b1e29faee912c5578040abb914a3e50e3749249
Author: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 22:07:42 2024 +0800
add docker info
commit 005b95d954d811ae67a219e8cb377766f44fe968
Author: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 20:06:50 2024 +0800
add go.mod
[root@prometheus-server31 devops]#
三.同步所有的标签到远程仓库
1.将本地仓库的tag信息推送到远程仓库
[root@prometheus-server31 devops]# git push origin --tags
Username for 'https://gitee.com': jasonyin2020
Password for 'https://jasonyin2020@gitee.com':
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 346 bytes | 346.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 65453081
To https://gitee.com/jasonyin2020/yinzhengjie-devops-k8s.git
* [new tag] Flink-v2.0 -> Flink-v2.0
* [new tag] Kafka-v3.8.0 -> Kafka-v3.8.0
[root@prometheus-server31 devops]#
2.在Gitee上查看某个标签的数据
如上图所示,我们把标签推送成功了,当然我们可以下载对应标签的程序包哟。
四.其他节点从远程仓库拉取最新的标签
[root@prometheus-server31 yinzhengjie-devops-k8s]# git branch
* flink
[root@prometheus-server31 yinzhengjie-devops-k8s]#
[root@prometheus-server31 yinzhengjie-devops-k8s]# git tag
[root@prometheus-server31 yinzhengjie-devops-k8s]#
[root@prometheus-server31 yinzhengjie-devops-k8s]# git pull origin --tags # 这里会拉取所有的标签哟
remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (2/2), 326 bytes | 326.00 KiB/s, done.
From gitee.com:jasonyin2020/yinzhengjie-devops-k8s
* [new tag] Flink-v2.0 -> Flink-v2.0
* [new tag] Kafka-v3.8.0 -> Kafka-v3.8.0
Already up to date.
[root@prometheus-server31 yinzhengjie-devops-k8s]#
[root@prometheus-server31 yinzhengjie-devops-k8s]# git tag
Flink-v2.0
Kafka-v3.8.0
[root@prometheus-server31 yinzhengjie-devops-k8s]#
[root@prometheus-server31 yinzhengjie-devops-k8s]# git show Kafka-v3.8.0
tag Kafka-v3.8.0
Tagger: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 23:02:57 2024 +0800
Kafka v3.8.0版本发布
commit 932ec59bbff547666f92aff82f691ac030d2fd86 (tag: Kafka-v3.8.0, origin/kafka)
Author: jasonyin2020 <y1053419035@qq.com>
Date: Sun Nov 17 22:37:29 2024 +0800
add kafka
diff --git a/kafka.log b/kafka.log
new file mode 100644
index 0000000..3ae0ead
--- /dev/null
+++ b/kafka.log
@@ -0,0 +1 @@
+https://kafka.apache.org/
[root@prometheus-server31 yinzhengjie-devops-k8s]#
五.删除标签
如上图所示,如果想要删除远程仓库的标签,则需要在WebUI操作即可,本地的标签基于命令行删除即可。
本地删除标签的具体操作如下所示:
[root@prometheus-server31 yinzhengjie-devops-k8s]# git tag
Flink-v2.0
Kafka-v3.8.0
[root@prometheus-server31 yinzhengjie-devops-k8s]#
[root@prometheus-server31 yinzhengjie-devops-k8s]# git tag -d Kafka-v3.8.0
Deleted tag 'Kafka-v3.8.0' (was bd02cc1)
[root@prometheus-server31 yinzhengjie-devops-k8s]#
[root@prometheus-server31 yinzhengjie-devops-k8s]# git tag
Flink-v2.0
[root@prometheus-server31 yinzhengjie-devops-k8s]#
当你的才华还撑不起你的野心的时候,你就应该静下心来学习。当你的能力还驾驭不了你的目标的时候,你就应该沉下心来历练。问问自己,想要怎样的人生。
欢迎交流学习技术交流,个人微信: "JasonYin2020"(添加时请备注来源及意图备注)
作者: 尹正杰, 博客: https://www.cnblogs.com/yinzhengjie/p/14300772.html