Git打标签

git标签分为两种:轻量标签(lightweight)和附注标签(annotated)。
轻量标签:只是一个特定提交的引用,不会存储任何信息。
附注标签:会包含打标签者的名字、电子邮件地址、日期时间、还有标签信息。

显示标签信息

$ git tag
v0.1
v1.3
v1.4

使用git show命令可以查看指定tag

$ git show v1.4
tag v1.4
Tagger: Ben Straub <ben@straub.cc>
Date:   Sat May 3 20:19:12 2014 -0700

my version 1.4

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

创建一个附注标签:

不在末尾指定校验和就是将标签打在最近一次commit上。

git tag -a v1.4 -m "my version 1.4"

使用-a选项创建一个附注标签, -m选项后是存储在标签中的信息。

创建一个轻量标签:

创建轻量标签,不需要使用-a, -s或-m选项,只需要提供标签名字:

git tag v1.0

共享标签

共享标签即将标签推送到远程仓库,默认情况下git push命令不会传送标签到远程服务器上。
推送某个tag到服务器:git push origin [tagname]

git push origin v1.5

推送所有标签到服务器:git push origin --tags

git push origin --tags

删除标签

删除一个标签并同步到远程仓库

#删除标签v1.0
git tab -d v1.0
# 同步删除到远程仓库
git push origin :refs/tags/v1.0

检出标签

如果要查看某个标签所指向的文件的版本,可以使用git checkout命令,使用这种方式后会使仓库处于“分离头指针(detacthed HEAD)”状态,这个状态有点儿副作用,在这种状态下作了修改并提交它们,标签不会发生变化,新提交不会属于任何分支,并且将无法访问,除非确切的提交哈希。

$ git checkout v1.0
Note: switching to 'v1.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 188b7ba new message
Rench@DESKTOP-I532HP0 MINGW64 /d/learnGit/test ((v1.0))
$ git status
HEAD detached at v1.0
nothing to commit, working tree clean

将某个标签检出为新分支

# version2是分支名称  v1.0是标签名
git checkout -b version2 v1.0
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这篇笔记是为了学习Git知识而收集总结的,主要是看受一篇帖子《你可能不知道的15条Git命令》的影响,才想记录这篇...
    WEB全栈开发陈老师阅读 1,324评论 0 0
  • 用途:像其他版本控制系统(VCS)一样,Git 可以给历史中的某一个提交打上标签,以示重要。 比较有代表性的是人们...
    我们都会更好的_b3fc阅读 340评论 0 0
  • 了解 Linux 常见命令 在使用 git 前,建议事先熟悉一些常见的 bash 命令 进入xxx目录$ cd x...
    acc8226阅读 621评论 0 1
  • 2. Git 基础 写在前面:这一部分内容真的是好多好多好多ε(┬┬﹏┬┬)3,不过也是使用 Git 最有用的啦,...
    sylvia_yue阅读 338评论 0 2
  • 一、基本概念: 注:对于git的分布式概念及其优点,不重复说明,自己百度或谷歌。本文中涉及到指令前面有$的,在cm...
    大厂offer阅读 1,451评论 0 3