美文网首页
Git打标签

Git打标签

作者: 走过分叉路 | 来源:发表于2019-12-18 15:29 被阅读0次

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 使用

    1.打标签 查看标签 git tag 打标签 git tag -a amc_1.0.0 -m '这是一个tag' ...

  • (十八)创建标签

    在Git中打标签非常简单,首先,切换到需要打标签的分支上: $git branch* dev master$git...

  • 创建标签

    在Git中打标签非常简单,首先,切换到需要打标签的分支上: $git branch* dev master$git...

  • Git 标签管理

    标签管理 创建标签 在Git中打标签需要先切换到需要打标签的分支上: 然后,敲命令 git tag ...

  • git 学习笔记(三)

    1.创建标签,首先切换到要打标签的分支$ git checkout master打一个新的标签$ git tag ...

  • git-tag

    git tag 在当前层打标签git tag 查询所有标签git tag

  • git 打标签

    1. 查看tag #git tag 2. 查看指定版本的tag #git tag -l 如:git tag -...

  • git打标签

    用途:像其他版本控制系统(VCS)一样,Git 可以给历史中的某一个提交打上标签,以示重要。 比较有代表性的是人们...

  • Git打标签

    Git打标签用途 Git打标签一般用于新提交一个版本后,给这个版本打个标签,以后如果需要恢复到这个版本,查找起来会...

  • Git打标签

网友评论

      本文标题:Git打标签

      本文链接:https://www.haomeiwen.com/subject/dplunctx.html