Files
GitGuide/docs/git/base/标签设置.md
2021-03-18 17:06:57 +08:00

140 lines
3.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 标签设置
`git``log`设置的基础上添加了标签设置,其目的是标识重要的提交记录(比如标识发布版本)
*下面以[opencv版本库](https://github.com/opencv/opencv)为例*
## 标签分类
标签分为两种
1. 注解标签(`annotated tag`)
2. 命名标签(`named tag`)
注解标签用于版本管理,命名标签用于私有或者临时标注。注解标签包含创建日期、标签名、`e-mail`、标签信息和可选的`GPG`签名
命名标签仅包含标签名,所以称为轻量级标签(`lightweight tag`
## 创建标签
常用参数如下:
1. `-a, --annotate`:生成一个未签名的注解标签对象
2. `-s, --sign`生成一个GPG签名的标签使用默认`e-mail`地址作为键
3. `-u <keyid>, --local-user=<keyid>`:生成一个`GPG`签名的标签,使用给定的键
4. `-m <msg>, --message=<msg>`:添加标签消息
5. `-F <file>, --file=<file>`:带有标签消息的文件
### 注解标签
使用上述参数`-a`/`-s`/`-u`生成的标签称`.git/refs/tags`标签,注解标签必须添加消息,可以使用参数`-m`或者`-F`,否则会打开一个编辑器
$ git tag -a v1.1 -m "添加一个注解标签"
### 命名标签
不使用任何参数,直接添加标签名的就是命名标签
$ git tag v1.1
### 给过去提交记录创建标签
默认给当前记录创建标签,还可以给过去记录创建标签
查看记录
$ git log --pretty=oneline
9e1b1e5389237c2b9f6c7b9d7715d9836c0a5de1 OpenCV 3.4.2
a0baae8a559d31c22ae08976b41cc99e046ba52b Merge pull request #11875 from dkurt:dnn_fix_reshape
9a66331984c5b0f0a71d6208a8237fc410ae923e Merge pull request #11882 from alalek:videoio_vfw_lower_priority
...
...
打标签时指定提交签名(*头几位就行了*)
$ git tag v0.3 0660c1108f969a -a -m "给过去提交记录打标签"
## 查看标签
查看所有标签
$ git tag
2.2
...
...
4.0.1
4.0.1-openvino
查看指定系列标签,使用参数`-l`
# 列出4.x版本
$ git tag -l 4.*
4.0.0
4.0.0-alpha
4.0.0-beta
4.0.0-openvino
4.0.0-rc
4.0.1
4.0.1-openvino
查看某一标签信息
$ git show 标签名
# 对于注解标签而言
$ git show 4.0.0
tag 4.0.0 # 标签名
Tagger: Alexander Alekhin <alexander.a.alekhin@gmail.com> # 标签者
Date: Sun Nov 18 09:19:48 2018 +0000 # 标签日期
OpenCV 4.0.0 # 标签信息
...
...
# 对于命名标签而言
$ git show v1.1 # 仅显示提交记录
commit a92571f31ddc7ea959b99e129f6c4705a404c36b
Author: zhujian <505169307@qq.com>
Date: Thu Feb 28 20:37:01 2019 +0800
## 共享标签
`github`利用标签进行`github release`的发布
但是默认情况下不会传输标签到远程托管服务器,需要单独显式推送
$ git push origin v1.0
# 或者全部推送
$ git push origin --tags
## 文件解析
创建的标签在`.git/refs/tags`文件夹下
## 删除标签
### 本地删除
使用参数`-d`来删除标签
$ git tag -d v1.1
Deleted tag 'v1.1' (was a92571f)
### 远程删除
同样需要单独显式删除远程标签
# 删除版本v1.1
$ git push origin :refs/tags/v1.1
## 切换标签
切换到指定标签,创建分支同时指定标签名
```
# 利用标签内容创建分支,并切换到分支
$ git checkout -b 分支名 标签名
```
## 相关阅读
* [2.6 Git 基础 - 打标签](https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE)