1.Git标签管理

当版本仓库内的数据有个大的改善或者功能更新,我们经常会打一个类似于软件版本号的标签,这样通过标签就可以将版本库中的某个历史版本给记录下来,方便我们随时将特定历史时期的数据取出来用,另外打标签其实只是像某个历史版本做了一个指针,所以一般都是瞬间完成的。

1.1创建本地标签

创建带有说明的标签,-a指定标签名字,-m指定说明文字

[root@git-node5 demo]# git tag -a v1.0.0 -m "version 1.0.0 release"

1.2查看本地标签

1.查看当前本地所有标签

[root@git-node5 demo]# git tag -l v*
v1.0.0
v1.0.1

2.查看当前1.0版本的详细信息

[root@linux-node5 shell]# git show v1.0.0
tag v1.0.0
Tagger: liyanzhao <1210353303@qq.com>
Date:   Fri Mar 29 10:51:13 2019 +0800

version 1.0.0 release

commit a4da598e9f54de780455f6f6e7b45a84ae32b73c
Author: liyanzhao <1210353303@qq.com>
Date:   Fri Mar 29 10:07:41 2019 +0800

    readme update

diff --git a/README.md b/README.md
index 6930653..9da586a 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,3 @@
 # shell
 大部分所有案例均出自《Linux命令行与shell脚本编程大全案例》一书,方便各位小伙伴学习,欢迎各位同学共同扩充shell脚本库哦!!!!
+nihao

1.3删除本地标签

我们为同一个提交版本设置了两次标签,删除重复性的标签

[root@linux-node5 shell]# git tag -d v1.0.1
Deleted tag 'v1.0.1' (was 1ae3a1a)
[root@git-node5 demo]# git tag -l v*
v1.0.0

1.4推送本地标签

如上操作都是基于打标签以及删除标签,下面我们来学习下打完标签后如何推送至远端服务器
也可以使用git push origin –-tags推送所有本地建立的tag包

root@linux-node5 shell]# git push origin v1.0.0
Username for 'https://github.com': 1210353303@qq.com
Password for 'https://1210353303@qq.com@github.com': 
Counting objects: 1, done.
Writing objects: 100% (1/1), 167 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/sunrisenan/shell.git
 * [new tag]         v1.0.0 -> v1.0.0

1.5获取远程标签

使用git pull获取最新tag包,可以使用git fetch强制获取

[root@linux-node5 shell]# git pull origin v1.0.0
From https://github.com/sunrisenan/shell
 * tag               v1.0.0     -> FETCH_HEAD
Already up-to-date.

1.6删除远程标签

通过push delete参数来删除远程标签

[root@linux-node5 shell]# git push origin --delete tag v1.0.0
Username for 'https://github.com': 1210353303@qq.com
Password for 'https://1210353303@qq.com@github.com': 
To https://github.com/sunrisenan/shell.git
 - [deleted]         v1.0.0

也可以先删除本地tag标签,然后推送空标签至于远程进行删除

[root@linux-node5 shell]# git tag v1.0.1
[root@linux-node5 shell]# git push origin v1.0.1
Username for 'https://github.com': 1210353303@qq.com
Password for 'https://1210353303@qq.com@github.com': 
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/sunrisenan/shell.git
 * [new tag]         v1.0.1 -> v1.0.1

//删除本地tag
[root@linux-node5 shell]# git tag -d v1.0.1
Deleted tag 'v1.0.1' (was a4da598)
//推送空tag至远程进行删除
[root@linux-node5 shell]# git push origin :refs/tags/v1.0.1
Username for 'https://github.com': 1210353303@qq.com
Password for 'https://1210353303@qq.com@github.com': 
To https://github.com/sunrisenan/shell.git
 - [deleted]         v1.0.1

1.7Git标签小结

git版本号规则

内部版本 B1.1.0
外部版本 V1.1.0
补丁版本 P1.1.0

命令git tag –a <tagname> -m "message" //在当前commit状态新建一个tag
命令git tag -l <tagname>   //列出相对应版本号tag
命令git push origin <tagname>      //推送一个本地标签
命令git push origin --tags //推送全部未推送过的本地标签
命令git tag -d <tagname>   //删除一个本地标签
命令git push origin --delete tag <tagname> //删除一个远程标签
命令git push origin :refs/tags/<tagname>   //删除一个远程标签
文档更新时间: 2019-03-29 11:03   作者:李延召