源站信息: 老姜博客 Git讲之git tag
git tag
主要的目的用来对指定的commit对象进行打标标记,便于事后回顾或者信息维护.
tag信息保存在:
.git/refs/tags/
git中git分为两种:
- lightweight tags:类似于branch,只不过branch随着commit不断提交,所指向的commit自动向前推进,而tag则不会,它将固定保存指定标签的commit对象
- annotated tags:功能上同
lightweight tags
,唯一的区别在于,前者只保存commit的hash值,而annotated tags
除了保存commit的hash值之外,还记录着打标人信息以及可供自由输入的自定义信息.
两种tag创建方式主要体现在命令的参数上,如果加上 -a
,则表示创建annotated tag
, 否则是lightweight tag
.
创建annotated tag
$ git lg1
* 5ede504 - (20 hours ago) add log file - jiangjian (HEAD -> master, dev)
* 3ca8f94 - (20 hours ago) add 1.py file - jiangjian
* be57548 - (21 hours ago) add README.txt - jiangjian
$ git tag -a v3
$ ls .git/refs/tags/
v3
$ cat .git/refs/tags/v3
4efe93475810990930a1dcb1db95d5261db2ef2a #annotated tag创建新的对象
$ git cat-file -t 4efe93475810990930a1dcb1db95d5261db2ef2a
tag #新创建的对象类型是:tag
$ git cat-file -p 4efe93475810990930a1dcb1db95d5261db2ef2a
object 5ede5043e4d3037c691f3344a2dfda4ec82b869a
type commit
tag v3
tagger jiangjian <jiangjian199204@gmail.com> 1608181297 +0800
Tag Author: jiangjian
Content: recommend to deliver
Version: v3
Date: 2020/12/17
Approval Status: Pass
Dept: Tech Group A
创建lightweight tag
$ git lg1
* 5ede504 - (20 hours ago) add log file - jiangjian (HEAD -> master, tag: v3, dev)
* 3ca8f94 - (20 hours ago) add 1.py file - jiangjian
* be57548 - (21 hours ago) add README.txt - jiangjian
$ git tag alpha
$ ls .git/refs/tags/
alpha v3
$ cat .git/refs/tags/alpha
5ede5043e4d3037c691f3344a2dfda4ec82b869a #注意这个和anotated tag有明显的区别,这里仅仅是其他commit的hash值
$ git cat-file -t 5ede5043e4d3037c691f3344a2dfda4ec82b869a
commit