update git tag post formatting

This commit is contained in:
Ariejan de Vroom 2020-03-11 13:35:20 +01:00
parent dcecff4207
commit 1bf31a2e83

View File

@ -9,73 +9,89 @@ Just as a kind of mini cheat sheet for using git tags. <a href="http://ariejan.n
Git has three different type of tags: Git has three different type of tags:
<ul> * Lightweight tags
<li>Lightweight tags</li> * Annotated tags
<li>Annotated tags</li> * Signed tags
<li>Signed tags</li>
</ul>
Let's start with lightweight tags. Let's start with lightweight tags.
<strong>Lightweight tags</strong> ## Lightweight tags
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. 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: Creating a lightweight tag is easy:
<code>git tag tag_name</code> ```
git tag tag_name
```
Viewing available tags is done with <code>-l</code>: Viewing available tags is done with <code>-l</code>:
<code>git tag -l</code> ```
git tag -l
```
<strong>Annotated tags</strong> ## Annotated tags
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. 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> ```
git tag -a tag_name
```
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. 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> ```
git tag -a -m "Tagging release 1.0" v1.0
```
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: 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> ```
git tag -l -n1
```
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! 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
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. 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: 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> ```
git tag -s -m "Tagging release 2.0" v2.0
```
The <code>-s</code> options implies the <code>-a</code> option, so here too a message is required. 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: To verify a signed tag you can run the following:
<code>git tag -v v2.0</code> ```
git tag -v v2.0
```
<strong>Deleting tags</strong> ## Deleting tags
There are times when you want to remove tags as well. This quite easy: There are times when you want to remove tags as well. This quite easy:
<code>git tag -d tag_name</code> ```
git tag -d tag_name
```
To remove a tag on a remote repository, you should do a special push: To remove a tag on a remote repository, you should do a special push:
<code>git push origin :refs/tags/tag_name</code> ```
git push origin :refs/tags/tag_name
```
<strong>Pushing tags</strong> ## Pushing tags
<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: To push your tags to a remote repository, use the following command to push all tags:
<code>git push origin --tags</code> ```
git push origin --tags
```
Happy tagging! Happy tagging!