tag标签

打标签

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 
Date:   Sat Dec 16 14:14:10 2017 +0800

test tag

commit 439ac73c29a0fe1c10fd975dc48f766e54e20654 (tag: v1.1)
Author: yin 
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 
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 

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'

你可能感兴趣的:(tag标签)