[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>前言
最近使用git来管理一个项目,到达一定阶段后,需要将稳定的代码发布成一个版本,经过查找资料发现git的标签操作刚好满足我的要求,所以记录下来,方便以后是使用查找。
<>用途
标签可以针对某一时间点的版本做标记,常用于版本发布,这恰恰是我所需要的功能,将本地标签推送到Github上即发布了一个Release版本,下载和查看非常方便。
<>标签分类
git标签分为两种类型:轻量标签和附注标签。轻量标签是指向提交对象的引用,附注标签则是仓库中的一个独立对象,建议使用附注标签,日后还可以查看标签信息。
<>创建标签
*
创建轻量标签
$ git tag v0.2.0 -light
解释:创建轻量标签不需要传递参数,直接指定标签名称即可。
*
创建附注标签
$ git tag -a v0.1.0 -m "release 0.1.0 version"
解释:创建附注标签时,参数-a即annotated的缩写,指定标签类型,后附标签名。参数m指定标签说明,说明信息会保存在标签对象中。
<>查看标签
*
列出当前仓库的所有标签
$ git tag
*
列出符合模式的标签
$ git tag -l 'v0.1.*'
*
查看标签版本信息
$ git show v0.1.0
<>切换标签
*
切换标签与切换分支命令相同
$ git checkout [tagname]
解释:切换标签后处于一个空的分支上,即"You are in ‘detached HEAD’ state."
<>删除标签
*
误打或需要修改标签时,需要先将标签删除,再打新标签
$ git tag -d v0.1.2
解释:参数-d即delete的缩写,意为删除其后指定的标签。
<>补打标签
*
给指定的commit打标签
$ git tag -a v0.1.0 49e0cd22f6bd9510fe65084e023d9c4316b446a6
解释:打标签不必要在HEAD之上,也可在之前的版本上打,这需要你知道某个提交对象的校验和,通过git log命令获取。
<>发布标签
*
将v0.1.0标签提交到git服务器
$ git push origin v0.1.0
解释:通常的git push不会将标签对象提交到git服务器,我们需要进行显式的操作。
*
将本地所有标签一次性提交到git服务器
$ git push origin --tags