git tag的相关操作

通常在发布软件的时候打一个tag,tag会记录版本的commit号,方便后期回溯。

列出标签

可以输入 git tag (可带上可选的 -l 选项 --list)

git tag

git tag -l 

git tag --list
git tag

git tag -l 

git tag --list

以按照特定的模式查找标签

git tag -l "v2.0.5*"
git tag -l "v2.0.5*"

创建标签

Git 支持两种标签:轻量标签(lightweight)与附注标签(annotated)。

轻量标签很像一个不会改变的分支——它只是某个特定提交的引用。

而附注标签是存储在 Git 数据库中的一个完整对象, 它们是可以被校验的,其中包含打标签者的名字、电子邮件地址、日期时间, 此外还有一个标签信息,并且可以使用 GNU Privacy Guard (GPG)签名并验证。 通常会建议创建附注标签,这样你可以拥有以上所有信息。但是如果你只是想用一个临时的标签, 或者因为某些原因不想要保存这些信息,那么也可以用轻量标签。

附注标签

运行 tag 命令时指定 -a 选项:

git tag -a release-1.0.0 -m 'commit msg'
git tag -a release-1.0.0 -m 'commit msg'

-m 选项指定了一条将会存储在标签中的信息。 如果没有为附注标签指定一条信息,Git 会启动编辑器要求你输入信息

使用 git show 命令可以看到标签信息和与之对应的提交信息:

Tagger: vincent <vincent.cy@foxmail.com>
Date:   Sat Oct 2 23:11:57 2021 +0800

test commit msg

commit d8f889280dc6f15a5ab417ac098b5cd5e2b35475 (HEAD -> master, tag: test_v1, origin/master)
authorId: vincent <vincent.cy@foxmail.com>
Date:   Wed Sep 15 13:53:11 2021 +0800


Tagger: vincent <vincent.cy@foxmail.com>
Date:   Sat Oct 2 23:11:57 2021 +0800

test commit msg

commit d8f889280dc6f15a5ab417ac098b5cd5e2b35475 (HEAD -> master, tag: test_v1, origin/master)
authorId: vincent <vincent.cy@foxmail.com>
Date:   Wed Sep 15 13:53:11 2021 +0800


输出显示了打标签者的信息、打标签的日期时间、附注信息,然后显示具体的提交信息。

轻量标签

轻量标签本质上是将提交校验和存储到一个文件中——没有保存任何其他信息。 创建轻量标签,不需要使用 -a、-s 或 -m 选项,只需要提供标签名字:

authorId: vincent <vincent.cy@foxmail.com>
Date:   Wed Sep 15 13:53:11 2021 +0800

cicd

diff --git a/Dockerfile b/Dockerfile
index 66db4f2..80371bf 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -16,7 +16,7 @@ COPY --from=deps /app/node_modules ./node_modules
 RUN yarn build

 ## copy file
-COPY ./blog.conf /etc/nginx/conf.d/
+# COPY ./blog.conf /etc/nginx/conf.d/
 #COPY /etc/nginx/cert/wekic_com /etc/nginx/conf.d/

 # Production image, copy all the files and run next
authorId: vincent <vincent.cy@foxmail.com>
Date:   Wed Sep 15 13:53:11 2021 +0800

cicd

diff --git a/Dockerfile b/Dockerfile
index 66db4f2..80371bf 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -16,7 +16,7 @@ COPY --from=deps /app/node_modules ./node_modules
 RUN yarn build

 ## copy file
-COPY ./blog.conf /etc/nginx/conf.d/
+# COPY ./blog.conf /etc/nginx/conf.d/
 #COPY /etc/nginx/cert/wekic_com /etc/nginx/conf.d/

 # Production image, copy all the files and run next

后期打标签

如果想对之前挖忘记打的标签重新打上。

commit 18eaf873b1529a83436fc3fd3faa27a735134e9e
authorId: vincent <vincent.cy@foxmail.com>
Date:   Thu Sep 9 10:25:44 2021 +0800

    port

commit 3e3c59227bfb529ce2f696a2f83d467c8aab6e2f
authorId: Vincent <vincent.cy@foxmail.com>
Date:   Thu Sep 9 10:07:54 2021 +0800

    Update README.md

commit dfd245f3df0ff1deb2b51c0f5129f0cff2446537
authorId: vincent <vincent.cy@foxmail.com>
Date:   Thu Sep 9 10:04:09 2021 +0800

    modify port

commit 03ea95b5683b3dfbe442be93ca32d4168a3af046


commit 18eaf873b1529a83436fc3fd3faa27a735134e9e
authorId: vincent <vincent.cy@foxmail.com>
Date:   Thu Sep 9 10:25:44 2021 +0800

    port

commit 3e3c59227bfb529ce2f696a2f83d467c8aab6e2f
authorId: Vincent <vincent.cy@foxmail.com>
Date:   Thu Sep 9 10:07:54 2021 +0800

    Update README.md

commit dfd245f3df0ff1deb2b51c0f5129f0cff2446537
authorId: vincent <vincent.cy@foxmail.com>
Date:   Thu Sep 9 10:04:09 2021 +0800

    modify port

commit 03ea95b5683b3dfbe442be93ca32d4168a3af046


通过 git tag -a version + commit

$ git tag -a v2.0 3e3c59227bfb529ce2f696a2f83d467c8aab6e2f
$ git tag -a v2.0 3e3c59227bfb529ce2f696a2f83d467c8aab6e2f

推送tag

推送单个tag

git push origin tag_name
git push origin tag_name

推送所有tag

这将会把所有不在远程仓库服务器上的标签全部传送到那里

git tag push origin --tags
git tag push origin --tags

删除标签

删除本地tag

git tag -d tag_name
git tag -d tag_name

删除远程标签

git push origin --delete tag_name
git push origin --delete tag_name

检出标签

git checkout tag_name
git checkout tag_name

操作参考