tag标签

作者: 竹铭_ | 来源:发表于2017-12-18 10:11 被阅读0次

打标签

Git 可以给历史中的某一个提交打上标签,以示重要。 比
较有代表性的是人们会使用这个功能来标记发布结点(v1.0 等等)

列出标签

git tag 列出所有标签
git tag -l 'v1.8*' 列出标签前面字符是v1.8的所有标签

$git tag -l  'v2.9*'
v2.9.0
v2.9.0-rc0
v2.9.0-rc1
v2.9.0-rc2
v2.9.1
v2.9.2
v2.9.3
v2.9.4
v2.9.5

创建标签

默认标签创建在最新提交的commit上

  • 轻量级标签 特定提交的一个引用
  • 附注标签 是存储在git库的一个完整对象,包括打标签者的姓名、邮箱、创建时间等(建议创建附注标签)

轻量级标签

# 创建
# 轻量级标签,不需要提供-a、-m、-s等参数,直接提供标签名
$ git tag test_lightweight

附注标签

# 创建
$ git tag -a v1.0 -m 'test tag v1.0'
# -a 添加附注标签
# -m 编写标签信息

-m 如果没有提供,git会运行编辑器要求你输入信息

追加(后期)打标签

# 查看提交纪录
$ git log --pretty=oneline
83428cee2f039c2cfd3a2cc93e952c2273c56e6f (HEAD -> master, origin/master, origin/HEAD) add e
a03793cc16833f2347538ddb455e6f273a026d62 add d
c909fd331b2dd74f4a031eb935b3ed4d7655bdf6 (tag: v1.2) add c

现在在add d上增加标签

$ git tag -a v1.3 a03793cc16833 -m 'add tag'
$ git log --pretty=oneline
83428cee2f039c2cfd3a2cc93e952c2273c56e6f (HEAD -> master, origin/master, origin/HEAD) add e
a03793cc16833f2347538ddb455e6f273a026d62 (tag: v1.3) add d
c909fd331b2dd74f4a031eb935b3ed4d7655bdf6 (tag: v1.2) add c

查看标签

git show tag_name

# 附注标签的 tag show
$git show v1.1
tag v1.1
Tagger: yin <yjd48676@ly.com>
Date:   Sat Dec 16 14:14:10 2017 +0800

test tag

commit 439ac73c29a0fe1c10fd975dc48f766e54e20654 (tag: v1.1)
Author: yin <yjd48676@ly.com>
Date:   Sat Dec 16 14:13:17 2017 +0800

    add b


# 轻量级的 tag show
$git show  test_lightweight
commit d81250633475814521e66e78b102a501f3cf2ebe (tag: test_lightweight, tag: show)
Author: yin <yjd48676@ly.com>
Date:   Sat Dec 16 14:07:25 2017 +0800

    add a

共享标签(推送标签到远端服务器)

默认情况下git push并不会推送标签到远端服务器,在创建完标签后需要显示的推送标签到服务器上。
推一个标签git push origin [tagname]
推所有标签git push origin --tags

# 推一个标签
$ git push origin v1.3
Counting objects: 1, done.
Writing objects: 100% (1/1), 150 bytes | 150.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To github.com:JinduYin/test_git.git
 * [new tag]         v1.3 -> v1.3

# 推所有标签 同步本地的所有tag到服务器
$ git push origin --tags
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 272 bytes | 272.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To github.com:JinduYin/test_git.git
 * [new tag]         show -> show
 * [new tag]         test_lightweight -> test_lightweight
 * [new tag]         v1.1 -> v1.1
 * [new tag]         v1.2 -> v1.2

获取指定tag代码

git checkout tag_name 切换到某个tag

$ git checkout v1.2
Note: checking out 'v1.2'.

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 performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at c909fd3... add c

"detached HEAD" 状态
如果你想编辑此tag下的代码,上面的方法就不适用了
需要把tag的快照对应的代码拉取到一个新分支上

git checkout -b dev v1.2 在tag v1.2处新建分支

$ git checkout -b dev v1.2
Switched to a new branch 'dev'

相关文章

  • Git 删除远程 tag 防止恢复

    git tag 标签简介 1、git tag --list 列出所有的标签 2、git tag

  • 妙用TAG标签,让海量长尾关键词上首页!

    导读:什么是TAG标签?TAG标签有什么作用?TAG标签跟长尾关键词优化排名有什么关系?怎么合理的优化TAG标签?...

  • git tag使用

    查看标签 git tag 创建标签 git tag 标签名字 -m '消息内容'git tag -a crm-1....

  • GIt命令行

    一、Tag git tag 打印所有标签 git tag v1.0 -light 创建轻量级标签 git tag ...

  • git 使用

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

  • Git命令(5)

    显示已有标签 git tag 新建标签 git tag -a tagname -m "message" 删除标签 ...

  • git-tag

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

  • GitLab 打tag

    查看标签 git tag 创建标签 git tag 标签名字 -m '消息内容' 推送标签 git push or...

  • 常用HTML标签

    html标签 html标签HTML 元素指的是从开始标签(start tag)到结束标签(end tag)的所有代...

  • 史上最全HTML分类标签,看完不了解来砍我

    html标签 html标签HTML 元素指的是从开始标签(start tag)到结束标签(end tag)的所有代...

网友评论

      本文标题:tag标签

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