Git Object: Tag

Git Object: Tag

tag

A git tag can be used to give a name to a git commit . For example, when you finish beta for version 1.0, you might want to tag the current state as “1.0beta”. The tag includes:

  • The name of the tag (such as 1.0beta).
  • commit that the tag refers to (such as 126af20). If you don’t specify a particular commit you want to tag, the most recent commit will be used.
  • A tag message (such as “This is 1.0beta“).
  • The tagger’s name, email address and the time the tag was added.

Example tag

Let’s use the example git object store as shown in the git commit section:

commit

When we last left off, we had done a git commit which created the second commit object (the orange oval in the upper right of the above diagram with hash 7fd2d16). To tag the current state of the repository, type:

$ git tag 1.0beta -m "This is 1.0beta"
1.0beta

The -m allows you to add the text that goes along with the tag. You can see the details of a tag:

$ git cat-file -p 1.0beta
object 7fd2d163886aad0ebdb72b0df4d6cd7153653257
type commit
tag 1.0beta
tagger Tim Flagg <me@gitguys.com> Wed Feb 16 14:09:13 2011 -0800
This is 1.0beta

To tag the very first commit that was done (the orange oval in the upper left with hash 126af20 listed under the orange oval), you can specify that commit as the last argument to git tag:

$ git tag -m "This is 1.0alpha" 1.0alpha 126af20

tagged

To get a list of tags:

$ git tag -l
1.0alpha
1.0beta

To check out the files that were tagged 1.0alpha:

$ git checkout 1.0alpha

and poke around to see what was at that point in time.

To get back to the files from the 1.0beta tag:

$ git checkout 1.0beta

Tags Are Fast

Adding a tag to a git commit is very fast and simple: A git tag object is added to the git object store and the tagging operation is finished.

Contrast this with adding a tag to legacy version control systems, which result in much more behind-the-scenes work while you wait.

Other flavors of git tags

The above type of tags (1.0alpha and 1.0beta) are the most common:

  • They are annotated (as opposed to lightweight)
  • They are unsigned (as opposed to GPG-signed).

lightweight tag is:

  • Not stored in the git object store the database.
  • Can’t be GPG-signed.

The gpg signature of a signed tag can be checked/verified by using the git tag -v command.

Next: What’s the deal with the Git Index?
Previous: The Git Commit Object

Related:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值