git 标签管理

标签管理

tag git中的标签 主要作用就是给某条修改记录取一个让人容易记住的有意义的名字,它跟某个commit绑在一起。

创建标签

给某次修改打一个标签该如何操作呢?下面的例子演示了如何给当前版本,打标签

$ git  checkout  master
Switched to branch 'master'
Your branch is up to date with 'rigion/master'.
$git tag v1.0
$ git  tag
v1.0
bogon:git zhengbing$ git  log  --pretty=oneline
70edc45fc6118b1c9fbe1027b1160e0120468938 (HEAD -> master, tag: v1.0, rigion/master) fix  bug 1024
fc0536e853bc505d45375746a3df4d5fd4e2cfad delete no
4464110564988026594dd4263d707c10577074da Merge branch 'zhengbing_dev'
a2fb2cda5f71231c9c0dd3eea6c9d6b673121529 delete readme2.txt
e68db6ce2192645403c90a311c25cee52fcde1e7 resolved  fixed
c0264af950e75a512dc9895c9b3806c9ed4438ed & simple
db758c4fd8de9f31e87bcb81787f7fd20db977b5 AMD simple
f8ba521f52ca2b4f6510ec3a35d7929fcde8d937 add file  dev.txt
801d6f066eecf1270920a361659dd61db3257457 add mutiple  files
ceebf2660aa2eea2f6c4e96a78dd5be08f728f6c add file test.txt
65d43dc687b35173b2d312bf7b71eb7593bc88ca append of files
400bdba9be3de24fb6077ef573564b6998af5cc9 tracks files
e17c4d4d2d8d2893009f3e56e7711657055ef779 understand stage
7dc80a9b6475908835ab78562d7db68fda83757c append  GPL
56fb09bdfefc467e9b2f5aba2060c215c19f68c9 update  readme.tct
9235ffdcced6c829b3f0fb991d5548c14fe49dc7 add  readme.txt

那么如果要给之前的版本打标签呢?这应该是很平常的需求吧?git tag v0.9 <记录号>a2fb2cda

$ git tag v0.9 a2fb2cda
$ git  log --pretty=oneline
70edc45fc6118b1c9fbe1027b1160e0120468938 (HEAD -> master, tag: v1.0, rigion/master) fix  bug 1024
fc0536e853bc505d45375746a3df4d5fd4e2cfad delete no
4464110564988026594dd4263d707c10577074da Merge branch 'zhengbing_dev'
a2fb2cda5f71231c9c0dd3eea6c9d6b673121529 (tag: v0.9) delete readme2.txt
e68db6ce2192645403c90a311c25cee52fcde1e7 resolved  fixed
c0264af950e75a512dc9895c9b3806c9ed4438ed & simple
db758c4fd8de9f31e87bcb81787f7fd20db977b5 AMD simple
f8ba521f52ca2b4f6510ec3a35d7929fcde8d937 add file  dev.txt
801d6f066eecf1270920a361659dd61db3257457 add mutiple  files
ceebf2660aa2eea2f6c4e96a78dd5be08f728f6c add file test.txt
65d43dc687b35173b2d312bf7b71eb7593bc88ca append of files
400bdba9be3de24fb6077ef573564b6998af5cc9 tracks files
e17c4d4d2d8d2893009f3e56e7711657055ef779 understand stage
7dc80a9b6475908835ab78562d7db68fda83757c append  GPL
56fb09bdfefc467e9b2f5aba2060c215c19f68c9 update  readme.tct
9235ffdcced6c829b3f0fb991d5548c14fe49dc7 add  readme.txt

使用git tag 后面不跟参数的时候,可以查看当前版本库的标签

$ git tag
v0.9
v1.0

也可以使用 git show 查看所打的标签的详细信息

$ git show  v0.9
commit a2fb2cda5f71231c9c0dd3eea6c9d6b673121529 (tag: v0.9)
Author: zhengbing 
Date:   Sat Oct 19 17:42:46 2019 +0800

    delete readme2.txt

diff --git a/readme2.txt b/readme2.txt
deleted file mode 100644
index e69de29..0000000

和 git commit 一样 我们也可以给标签添加注释 同样使用git tag 命令 但是要加上参数了 -a 指定标签名 -m 添加注释

使用git show v0.8 可以看到我们给标签写的注释

$ git tag -a v0.8 -m 'finished september dev' f8ba521f5
$ git  tag
v0.8
v0.9
v1.0
$ git  show  v0.8
tag v0.8
Tagger: zhengbing 
Date:   Sun Oct 20 23:26:00 2019 +0800

finished september dev

commit f8ba521f52ca2b4f6510ec3a35d7929fcde8d937 (tag: v0.8)
Author: zhengbing 
Date:   Thu Oct 17 01:02:23 2019 +0800

    add file  dev.txt

diff --git a/dev.txt b/dev.txt
new file mode 100644
index 0000000..e69de29

操作标签

ok,如果打错了标签呢?我们可能要删除标签。需要用到 git tag -d

$ git tag -d v0.9
Deleted tag 'v0.9' (was a2fb2cd)

如果打的标签没有问题的话,那么我么就可以把本地的标签push到远程仓库进行管理

$ git push origin v1.0
Total 0 (delta 0), reused 0 (delta 0)
To github.com:zhengbinger/learngit.git
 * [new tag]         v1.0 -> v1.0

那么,如果远程的标签打错了呢?怎么删除呢?

先删除本地标签

$ git  tag  -d v1.0

再删除远程标签,删除远程标签会比较复杂一点 git push origin :refs/tags/v1.0

$ git push origin :refs/tags/v1.0
To github.com:zhengbinger/learngit.git
 - [deleted]         v1.0

你可能感兴趣的:(git 标签管理)