Git 基础 - 打标签
打标签
同大多数 VCS 一样,Git 也可以对某一时间点上的版本打上标签。人们在发布某个软件版本(比如 v1.0 等等)的时候,经常这么做。本节我们一起来学习如何列出所有可用的标签,如何新建标签,以及各种不同类型标签之间的差别。
列显已有的标签
列出现有标签的命令非常简单,直接运行 git tag
即可:
$ git tag
v0.1
v1.3
显示的标签按字母顺序排列,所以标签的先后并不表示重要程度的轻重。
我们可以用特定的搜索模式列出符合条件的标签。在 Git 自身项目仓库中,有着超过 240 个标签,如果你只对 1.4.2 系列的版本感兴趣,可以运行下面的命令:
$ git tag -l 'v1.4.2.*'
v1.4.2.1
v1.4.2.2
v1.4.2.3
v1.4.2.4
新建标签
Git 使用的标签有两种类型:轻量级的(lightweight)和含附注的(annotated)。轻量级标签就像是个不会变化的分支,实际上它就是个指向特定提交对象的引用。而含附注标签,实际上是存储在仓库中的一个独立对象,它有自身的校验和信息,包含着标签的名字,电子邮件地址和日期,以及标签说明,标签本身也允许使用 GNU Privacy Guard (GPG) 来签署或验证。一般我们都建议使用含附注型的标签,以便保留相关信息;当然,如果只是临时性加注标签,或者不需要旁注额外信息,用轻量级标签也没问题。
含附注的标签
创建一个含附注类型的标签非常简单,用 -a
(译注:取 annotated
的首字母)指定标签名字即可:
$ git tag -a v1.4 -m 'my version 1.4'
$ git tag
v0.1
v1.3
v1.4
而 -m
选项则指定了对应的标签说明,Git 会将此说明一同保存在标签对象中。如果没有给出该选项,Git 会启动文本编辑软件供你输入标签说明。
可以使用 git show
命令查看相应标签的版本信息,并连同显示打标签时的提交对象。
$ git show v1.4
tag v1.4
Tagger: Scott Chacon <schacon@gee-mail.com>
Date: Mon Feb 9 14:45:11 2009 -0800
my version 1.4
commit 15027957951b64cf874c3557a0f3547bd83b3ff6
Merge: 4a447f7... a6b4c97...
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sun Feb 8 19:02:46 2009 -0800
Merge branch 'experiment'
我们可以看到在提交对象信息上面,列出了此标签的提交者和提交时间,以及相应的标签说明。
签署标签
如果你有自己的私钥,还可以用 GPG 来签署标签,只需要把之前的 -a
改为 -s
(译注: 取 signed
的首字母)即可:
$ git tag -s v1.5 -m 'my signed 1.5 tag'
You need a passphrase to unlock the secret key for
user: "Scott Chacon <schacon@gee-mail.com>"
1024-bit DSA key, ID F721C45A, created 2009-02-09
现在再运行 git show
会看到对应的 GPG 签名也附在其内:
$ git show v1.5
tag v1.5
Tagger: Scott Chacon <schacon@gee-mail.com>
Date: Mon Feb 9 15:22:20 2009 -0800
my signed 1.5 tag
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
iEYEABECAAYFAkmQurIACgkQON3DxfchxFr5cACeIMN+ZxLKggJQf0QYiQBwgySN
Ki0An2JeAVUCAiJ7Ox6ZEtK+NvZAj82/
=WryJ
-----END PGP SIGNATURE-----
commit 15027957951b64cf874c3557a0f3547bd83b3ff6
Merge: 4a447f7... a6b4c97...
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sun Feb 8 19:02:46 2009 -0800
Merge branch 'experiment'
稍后我们再学习如何验证已经签署的标签。
轻量级标签
轻量级标签实际上就是一个保存着对应提交对象的校验和信息的文件。要创建这样的标签,一个 -a
,-s
或 -m
选项都不用,直接给出标签名字即可:
$ git tag v1.4-lw
$ git tag
v0.1
v1.3
v1.4
v1.4-lw
v1.5
现在运行 git show
查看此标签信息,就只有相应的提交对象摘要:
$ git show v1.4-lw
commit 15027957951b64cf874c3557a0f3547bd83b3ff6
Merge: 4a447f7... a6b4c97...
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sun Feb 8 19:02:46 2009 -0800
Merge branch 'experiment'
验证标签
可以使用 git tag -v [tag-name]
(译注:取 verify
的首字母)的方式验证已经签署的标签。此命令会调用 GPG 来验证签名,所以你需要有签署者的公钥,存放在 keyring 中,才能验证:
$ git tag -v v1.4.2.1
object 883653babd8ee7ea23e6a5c392bb739348b1eb61
type commit
tag v1.4.2.1
tagger Junio C Hamano <junkio@cox.net> 1158138501 -0700
GIT 1.4.2.1
Minor fixes since 1.4.2, including git-mv and git-http with alternates.
gpg: Signature made Wed Sep 13 02:08:25 2006 PDT using DSA key ID F3119B9A
gpg: Good signature from "Junio C Hamano <junkio@cox.net>"
gpg: aka "[jpeg image of size 1513]"
Primary key fingerprint: 3565 2A26 2040 E066 C9A7 4A7D C0C6 D9A4 F311 9B9A
若是没有签署者的公钥,会报告类似下面这样的错误:
gpg: Signature made Wed Sep 13 02:08:25 2006 PDT using DSA key ID F3119B9A
gpg: Can't check signature: public key not found
error: could not verify the tag 'v1.4.2.1'
后期加注标签
你甚至可以在后期对早先的某次提交加注标签。比如在下面展示的提交历史中:
$ git log --pretty=oneline
15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment'
a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support
0d52aaab4479697da7686c15f77a3d64d9165190 one more thing
6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment'
0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
4682c3261057305bdd616e23b64b0857d832627b added a todo file
166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
我们忘了在提交 “updated rakefile” 后为此项目打上版本号 v1.2,没关系,现在也能做。只要在打标签的时候跟上对应提交对象的校验和(或前几位字符)即可:
$ git tag -a v1.2 9fceb02
可以看到我们已经补上了标签:
$ git tag
v0.1
v1.2
v1.3
v1.4
v1.4-lw
v1.5
$ git show v1.2
tag v1.2
Tagger: Scott Chacon <schacon@gee-mail.com>
Date: Mon Feb 9 15:32:16 2009 -0800
version 1.2
commit 9fceb02d0ae598e95dc970b74767f19372d61af8
Author: Magnus Chacon <mchacon@gee-mail.com>
Date: Sun Apr 27 20:43:35 2008 -0700
updated rakefile
...
分享标签
默认情况下,git push
并不会把标签传送到远端服务器上,只有通过显式命令才能分享标签到远端仓库。其命令格式如同推送分支,运行 git push origin [tagname]
即可:
$ git push origin v1.5
Counting objects: 50, done.
Compressing objects: 100% (38/38), done.
Writing objects: 100% (44/44), 4.56 KiB, done.
Total 44 (delta 18), reused 8 (delta 1)
To git@github.com:schacon/simplegit.git
* [new tag] v1.5 -> v1.5
如果要一次推送所有本地新增的标签上去,可以使用 --tags
选项:
$ git push origin --tags
Counting objects: 50, done.
Compressing objects: 100% (38/38), done.
Writing objects: 100% (44/44), 4.56 KiB, done.
Total 44 (delta 18), reused 8 (delta 1)
To git@github.com:schacon/simplegit.git
* [new tag] v0.1 -> v0.1
* [new tag] v1.2 -> v1.2
* [new tag] v1.4 -> v1.4
* [new tag] v1.4-lw -> v1.4-lw
* [new tag] v1.5 -> v1.5
现在,其他人克隆共享仓库或拉取数据同步后,也会看到这些标签。
2018年10月12日 05:34
That is one excellent painting. Even the dew drops on the petals look so realistic and attractive. Great work by the artist and congratulations to you for getting such a beautiful gift.
2021年8月29日 05:02
It is somewhat fantastic, and yet check out the advice at this treat.
2022年9月18日 06:32
The English language is very essential for every people to survive anywhere in this World. Learning the English language may not be done in a short period of time, it should begin from a foundation of Education to make students understand and learn the language without any difficulties.That’s the way there are a huge number of English Medium Schools are teaching English as the First language to their students and those Hindi Medium and Urdu Medium students have chosen English as their Second or Third Langauge. NCERT English Sample Paper Class 2 Those 2nd Standard students can download the NCERT English Sample Paper 2023 Class 2 designed based on the revised Syllabus and Curriculum.
2022年12月30日 19:38
After study many of the web sites for your internet site now, i really appreciate your strategy for blogging. I bookmarked it to my bookmark site list and will be checking back soon. Pls have a look at my web-site too and figure out what you consider. 노래방알바
2022年12月30日 19:39
You should get involved in a tournament for one of the best blogs on-line. I’ll recommend this web site! 강남셔츠룸
2023年1月01日 03:23
Respect to website author , some good selective information . 바카라사이트
2023年1月06日 03:35
Hey, nice post, really well written. You should write more about this. 토토사이트
========================
The gods do nothing until they’ve blinded the minds of the wicked. 메이저바카라
2023年1月09日 03:21
I impressed, I need to say. Really not often do I encounter a blog that each educative and entertaining, and let me tell you, you have hit the nail on the head. Your concept is outstanding; the problem is something that not sufficient persons are speaking intelligently about. I’m very comfortable that I stumbled across this in my seek for one thing referring to this. 여우알바
==================
A few of the pendant watches are constructed with real gold and silver, rhinestone or gemstones. 룸알바
2023年1月09日 05:38
Online Quran Learning for Kids & Adults with Expert Male & Female Quran Teachers. 100% Free Trial Classes & Up to 10% Siblings Discounts. https://livelearningquran.com/
2023年2月08日 03:00
Awesome! I thank you your blog post to this matter. It has been useful. software contracts
2023年12月21日 02:54
Our the purpose is to share the reviews about the latest Jackets,Coats and Vests also share the related Movies,Gaming, Casual,Faux Leather and Leather materials available
2023年12月24日 04:36
Nice creative fashion ideas. I think you are the only blogger concentrating mainly on men's costumes. No body cares about men's fashion. Thanks for sharing this good post. Keep sharing more interesting blogs like this.
2023年12月30日 18:43
"Great site! I really love the amazing way it is simple on my eyes it is. I am considering how I may be told at whatever point another post has been made. I have bought in to your RSS which may work? Have an incredible dayI think this is an enlightening post and it is exceptionally helpful and educated. in this manner. I might want to thank you for the endeavors you have made recorded as a hard copy this article.
"
2023年12月30日 19:20
That is genuinely something that we think about a ton. Right when we concocted our key game-plan, the central fragment was individuals. Hopkins is mind blowing in light of the general open who work here and learn here, so it's basic to use to keep them satisfied and secured.
2023年12月30日 19:31
https://www.totocri.com/mt-police/
2023年12月30日 19:41
That is truly something that we consider a ton. At the point when we thought up our key course of action, the fundamental segment was people. Hopkins is mind blowing because of the overall public who work here and learn here, so it's critical to use to keep them fulfilled and locked in.
2023年12月30日 19:55
A debt of gratitude is in order for all the exertion in sharing this splendid post and I truly to welcome it. Your commitment and diligent work has helped you to deliver great quality articles this way Cool stuff you have and you keep upgrade all of us
2023年12月30日 19:58
Hello what a dazzling post I have gone over and trust me I have been paying extraordinary personality to this comparative sort of post for late week and hardly continued running over this. Much thanks and will search for more postings from you.
2023年12月30日 20:18
his is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.
2023年12月30日 20:37
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
2023年12月30日 20:48
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
2023年12月30日 21:17
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
2023年12月30日 21:35
Incredible post. An obligation of appreciation is with the goal for offering to us. I just appreciated your technique for presentation. I acknowledged getting this .Thanks for sharing and keep forming. It is extraordinary to scrutinize sites this way. As usual, we invite yourself certification and recognize as legitimate inside us.
2023年12月30日 22:02
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
2023年12月30日 22:13
Hi I found your site by mistake when i was searching yahoo for this acne issue, I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
2023年12月30日 22:49
Hi I found your site by mistake when i was searching yahoo for this acne issue, I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
2023年12月30日 23:00
I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job! My friend mentioned to me your blog, so I thought I’d read it for myself.
2023年12月30日 23:03
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
2023年12月30日 23:33
with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
2023年12月30日 23:51
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
2023年12月31日 00:05
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
2023年12月31日 00:44
Much obliged to you again for all the learning you disperse, Good post. I was extremely intrigued by the article, it's very rousing I ought to concede. I like visiting your site since I generally go over intriguing articles this way one.
2023年12月31日 00:56
"Great site! I really love the amazing way it is simple on my eyes it is. I am considering how I may be told at whatever point another post has been made. I have bought in to your RSS which may work? Have an incredible dayI think this is an enlightening post and it is exceptionally helpful and educated. in this manner. I might want to thank you for the endeavors you have made recorded as a hard copy this article.
"
2023年12月31日 01:34
That is really something that we think about a ton. Right when we concocted our key strategy, the key section was individuals. Hopkins is mind blowing due to the general open who work here and learn here, so it's basic to use to keep them satisfied and secured.
2023年12月31日 01:53
That is truly something that we consider a ton. At the point when we thought up our key course of action, the fundamental segment was people. Hopkins is mind blowing because of the overall public who work here and learn here, so it's critical to use to keep them fulfilled and locked in.
2023年12月31日 02:12
That is truly something that we consider a ton. At the point when we thought up our key course of action, the fundamental segment was people. Hopkins is mind blowing because of the overall public who work here and learn here, so it's critical to use to keep them fulfilled and locked in.
2023年12月31日 02:33
A debt of gratitude is in order for all the exertion in sharing this splendid post and I truly to welcome it. Your commitment and diligent work has helped you to deliver great quality articles this way Cool stuff you have and you keep upgrade all of us
2023年12月31日 02:41
Hello what a dazzling post I have gone over and trust me I have been paying extraordinary personality to this comparative sort of post for late week and hardly continued running over this. Much thanks and will search for more postings from you.
2023年12月31日 03:12
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!You have raised an important issue..Thanks for sharing..I would like to read more current affairs from this blog..keep posting..
2023年12月31日 03:28
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
2023年12月31日 03:55
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
2023年12月31日 04:10
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
2023年12月31日 04:14
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
2023年12月31日 04:17
Incredible post. An obligation of appreciation is with the goal for offering to us. I just appreciated your technique for presentation. I acknowledged getting this .Thanks for sharing and keep forming. It is extraordinary to scrutinize sites this way. As usual, we invite yourself certification and recognize as legitimate inside us.
2023年12月31日 04:28
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
2023年12月31日 04:39
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates
2023年12月31日 04:42
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
2024年1月19日 20:01
All your hard work is much appreciated. Nobody can stop to admire you. Lots of appreciation
2024年1月19日 21:16
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well..
2024年1月19日 22:03
In the wake of perusing your article I was stunned. I realize that you clarify it exceptionally well. What's more, I trust that different perusers will likewise encounter how I feel in the wake of perusing your article.
2024年1月19日 22:19
This is the reason it really is greater you could important examination before creating. It will be possible to create better write-up like this.
2024年1月19日 22:55
I’ll be sure to come back.
2024年1月19日 23:29
Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.
2024年1月20日 00:22
This post is extremely easy to peruse and acknowledge without forgetting any subtle elements. Incredible work
2024年1月20日 01:04
This is a brilliant post I seen because of offer it. It is truly what I needed to see trust in future you will proceed for sharing such an amazing post
2024年1月20日 01:41
This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck
2024年1月20日 02:20
"nice post
thanks for sharing"
2024年1月20日 18:37
Great article! I truly enjoyed reading it!
2024年1月20日 19:08
very useful information thanks for sharing this great article
2024年1月20日 20:55
This is exciting, nevertheless it is vital for you to visit this specific url:
2024年1月20日 21:43
"Very nice post. I just stumbled upon your blog and wanted to say that I’ve really enjoyed browsing your
blog posts."
2024年1月25日 17:38
카지노사이트 바카라사이트 우리카지노 카지노는 바카라, 블랙잭, 룰렛 및 슬롯 등 다양한 게임을 즐기실 수 있는 공간입니다. 게임에서 승리하면 큰 환호와 함께 많은 당첨금을 받을 수 있고, 패배하면 아쉬움과 실망을 느끼게 됩니다.
2024年1月25日 17:45
하노이 꼭 가봐야 할 베스트 업소 추천 안내 및 예약, 하노이 밤문화 에 대해서 정리해 드립니다. 하노이 가라오케, 하노이 마사지, 하노이 풍선바, 하노이 밤문화를 제대로 즐기시기 바랍니다. 하노이 밤문화 베스트 업소 요약 베스트 업소 추천 및 정리.
2024年1月28日 16:44
No.1 먹튀검증 사이트, 먹튀사이트, 검증사이트, 토토사이트, 안전사이트, 메이저사이트, 안전놀이터 정보를 제공하고 있습니다. 먹튀해방으로 여러분들의 자산을 지켜 드리겠습니다. 먹튀검증 전문 커뮤니티 먹튀클린만 믿으세요!!
2024年1月28日 16:50
베트남 남성전용 커뮤니티❣️ 베트남 하이에나 에서 베트남 밤문화를 추천하여 드립니다. 베트남 가라오케, 베트남 VIP마사지, 베트남 이발관, 베트남 황제투어 남자라면 꼭 한번은 경험 해 봐야할 화끈한 밤문화로 모시겠습니다.
2024年1月28日 19:10
Thank you for the update, very nice site
2024年1月28日 19:21
It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing.
2024年1月28日 19:34
Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work..
2024年6月02日 20:30
The tech-original mission is to help you better understand technology, and make better decisions in the fields of IT, Tech, and Crypto.
https://www.tech-original.com/
2024年6月07日 16:07
The tech-original mission is to help you better understand technology, and make better decisions in the fields of IT, Tech, and Crypto.
https://www.tech-original.com/