目录
Git-Tagging
1. Listing Your Tags
1.1 Listing the existing tags
// 任意一中
$ git tag
$ git tag -l
$ git tag --list
// 执行结果
v1.0
v2.0
v2.1.0
v2.1.1
v2.1.2
v2.1.3
v2.2.0
v2.2.1
v3.0
v3.1
...
1.2 search for tags
$ git tag -l "v2.1*"
// 执行结果
v2.1.0
v2.1.1
v2.1.2
v2.1.3
如果需要用到通配符,必须携带
-l
或则--list
1.3 pull tags
获取远程tags,直接执行git fetch
即可
$ git fetch
From http://git.etonedu.cn/app/class/tags
* [new tag] v13.0 -> v13.0
* [new tag] v14.0 -> v14.0
2. Creating Tags
Git 支持两种标签:轻量标签(lightweight)与附注标签(annotated)。
轻量标签很像一个不会改变的分支——它只是某个特定提交的引用。
附注标签是存储在 Git 数据库中的一个完整对象, 它们是可以被校验的,其中包含打标签者的名字、电子邮件地址、日期时间, 此外还有一个标签信息,并且可以使用 GNU Privacy Guard (GPG)签名并验证。
2.1 Annotated Tags
// 创建附注标签
$ git tag -a v4.0 -m "just test version"
// 查看
$ git show v4.0
tag v4.0
Tagger: super <super@gmail.com>
Date: Thu Mar 24 10:31:41 2022 +0800
just test version
commit 872327ef14a108ed619c6a497507dbd9fa56e339 (HEAD -> master, tag: v5.0, tag: v4.0, tag: v3.1, tag: v3.0, tag: v2.2.1, tag: v2.2.0, tag: v2.1.3, tag: v2.1.2, tag: v2.1.1, tag: v2.1.0, tag: v2.0)
Author: super <super@gmail.com>
Date: Tue Mar 22 09:29:37 2022 +0800
update
diff --git a/test.md b/test.md
index 2d6058e..f58b194 100644
--- a/test.md
+++ b/test.md
@@ -1 +1,2 @@
Just Test
+Just Test
2.2 Lightweight Tags
// 创建轻量标签
$ git tag v4.1-lw
// 查看
$ git show v4.1-lw
commit 872327ef14a108ed619c6a497507dbd9fa56e339 (HEAD -> master, tag: v5.0, tag: v4.1-lw, tag: v4.0, tag: v3.1, tag: v3.0, tag: v2.2.1, tag: v2.2.0, tag: v2.1.3, tag: v2.1.2, tag: v2.1.1, tag: v2.1.0, tag: v2.0, tag: show)
Author: super <super@gmail.com>
Date: Tue Mar 22 09:29:37 2022 +0800
update
diff --git a/test.md b/test.md
index 2d6058e..f58b194 100644
--- a/test.md
+++ b/test.md
@@ -1 +1,2 @@
Just Test
+Just Test
3. Tagging Later
指定哈希值,直接添加tag即可
// 创建附注标签
$ git tag -a v8.0 ade7103 -m "history test"
// 创建轻量标签
$ git tag v8.0 ade7103
4. Sharing Tags
使用git push origin <tagname>
,推送到远程仓库(和推送新分支命令一致)
$ git push origin v1.0
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To http://git.etonedu.cn/app/class/tags.git
* [new tag] v1.0 -> v1.0
推送所有tag
$ git push origin --tags
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 524 bytes | 524.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
To http://git.etonedu.cn/app/class/tags.git
* [new tag] v4.0 -> v4.0
* [new tag] v5.0 -> v5.0
默认情况下,
git push
命令并不会传送标签到远程仓库服务器上。如果想要一次性推送很多标签,也可以使用带有--tags
选项的git push
命令(不会区分轻量标签和附注标签)
5. Deleting Tags
删除本地tag,使用git tag -d <tagname>
$ git tag -d v1.0
Deleted tag 'v1.0' (was e4899f5)
删除远程仓库tag,使用git push <remote> -d <tagname>
或则 git push <remote> :refs/tags/<tagname>
// 方法一
$ git push origin -d v1.0
To http://git.etonedu.cn/app/class/tags.git
- [deleted] v1.0
// 同方法一
$ git push origin --delete v3.0
To http://git.etonedu.cn/app/class/tags.git
- [deleted] v3.0
// 方法二
$ git push origin :v2.0
To http://git.etonedu.cn/app/class/tags.git
- [deleted] v2.0
// 同方法二
$ git push origin :refs/tags/v4.0
To http://git.etonedu.cn/app/class/tags.git
- [deleted] v4.0
6. Checking out Tags
可以直接checkout到某个tag,查看该版本对应的commit历史
$ git checkout v5.0
Note: switching to 'v5.0'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 872327e update
Super