82 lines
3.2 KiB
Markdown
82 lines
3.2 KiB
Markdown
|
+++
|
||
|
date = "2009-09-05"
|
||
|
title = "Git Tag Mini Cheat Sheet Revisited"
|
||
|
tags = ["git", "cheat sheet", "tags"]
|
||
|
slug = "git-tag-mini-cheat-sheet-revisited"
|
||
|
+++
|
||
|
|
||
|
Just as a kind of mini cheat sheet for using git tags. <a href="http://ariejan.net/2009/09/04/git-tag-mini-cheat-sheet/comment-page-1/#comment-10876">Jörg Mittag</a> had some great additions that weren't in the original post which warrant a new post.
|
||
|
|
||
|
Git has three different type of tags:
|
||
|
|
||
|
<ul>
|
||
|
<li>Lightweight tags</li>
|
||
|
<li>Annotated tags</li>
|
||
|
<li>Signed tags</li>
|
||
|
</ul>
|
||
|
|
||
|
Let's start with lightweight tags.
|
||
|
|
||
|
<strong>Lightweight tags</strong>
|
||
|
|
||
|
In the previous cheat sheet only the lightweight local tags were discussed. A lightweight tag is nothing more than a reference to a particular revision or SHA1 object name in the repository. This kind of tag is quick and easy and very usable for local development to mark places in your commit history.
|
||
|
|
||
|
Creating a lightweight tag is easy:
|
||
|
|
||
|
<code>git tag tag_name</code>
|
||
|
|
||
|
Viewing available tags is done with <code>-l</code>:
|
||
|
|
||
|
<code>git tag -l</code>
|
||
|
|
||
|
<strong>Annotated tags</strong>
|
||
|
|
||
|
Annotated tags are almost like lightweight tags, the big difference is that they contain a message. Normally this message indicated why this tag is interesting. Use the <code>-a</code> option to create an annotated tag.
|
||
|
|
||
|
<code>git tag -a tag_name</code>
|
||
|
|
||
|
Since a message is required for annotated tags, you will be prompted with an editor to enter a message, or you can use the <code>-m</code> option to specify one directly.
|
||
|
|
||
|
<code>git tag -a -m "Tagging release 1.0" v1.0</code>
|
||
|
|
||
|
To view annotated tags you can use the same <code>-l</code> option as before, but you have to instruct git to show the annotation messages as well:
|
||
|
|
||
|
<code>git tag -l -n1</code>
|
||
|
|
||
|
This will not only show the messages for the annotated tags, it will also show the commit message of the revisions tagged with lightweight tags as well. Quite useful!
|
||
|
|
||
|
<strong>Signed tags</strong>
|
||
|
|
||
|
Signed tags take annotated tags a step further, they include an OpenPG signature to provide trust. While gits SHA1 tags provide integrity for the repository, the OpenPG signature makes sure that a trustworthy person created the tag.
|
||
|
|
||
|
To create a signed tag you'll need to have GPG or some other OpenPG tool setup and use the <code>-s</code> option to sign the tag:
|
||
|
|
||
|
<code>git tag -s -m "Tagging release 2.0" v2.0</code>
|
||
|
|
||
|
The <code>-s</code> options implies the <code>-a</code> option, so here too a message is required.
|
||
|
|
||
|
To verify a signed tag you can run the following:
|
||
|
|
||
|
<code>git tag -v v2.0</code>
|
||
|
|
||
|
<strong>Deleting tags</strong>
|
||
|
|
||
|
There are times when you want to remove tags as well. This quite easy:
|
||
|
|
||
|
<code>git tag -d tag_name</code>
|
||
|
|
||
|
To remove a tag on a remote repository, you should do a special push:
|
||
|
|
||
|
<code>git push origin :refs/tags/tag_name</code>
|
||
|
|
||
|
<strong>Pushing tags</strong>
|
||
|
|
||
|
<a href="http://ariejan.net/2009/09/04/git-tag-mini-cheat-sheet/comment-page-1/#comment-10876">Jörg Mittag</a> claims that annotated and signed tags are pushed and fetched automatically. I have never seen a tag of any kind being pushed automatically, so I hope Jörg can clarify this further.
|
||
|
|
||
|
To push your tags to a remote repository, use the following command to push all tags:
|
||
|
|
||
|
<code>git push origin --tags</code>
|
||
|
|
||
|
Happy tagging!
|
||
|
|