Git - Tag
About
This page is about tagging in git
Git has the ability to tag specific points in history as being important. Typically this functionality is used to mark release points (v1.0, and so on).
Git uses two main types of tags:
- or lightweight
- By default, the git push command doesn’t transfer tags to remote servers.
- You can't add a new commit to a tag.
A tag is an object in git.
Type
Annotated
Annotated tags :
- are stored as full objects in the Git database.
- are checksummed;
- contain the tagger name, email, and date;
- have a tagging message;
- can be signed and verified with GNU Privacy Guard (GPG).
Lightweight
A lightweight tag is very much like a branch that doesn’t change – it’s just a pointer to a specific commit.
Lightweight tags are used:
- to create a temporary tag
- to not keep all tag meta information (as with the annotated tag version)
Property
Name
The tag name generally starts with a v and follow the semantic version: See Code Versioning - Versioning scheme
Management
Create
Annotated
git tag -a v1.4 9fceb02 -m "my version 1.4"
where:
- -a means annotated
- v1.4 is the tag name.
- 9fceb02 is the commit checksum or a part of it. See commit log. Default to the last commit.
- -m “my version 1.4” is the tagging message
Lightweight
To create a lightweight tag, don’t supply the -a, -s, or -m option.
git tag v1.4
Show
With show
git show v1.4
tag v1.4
Tagger: Ben Straub <[email protected]>
Date: Sat May 3 20:19:12 2014 -0700
my version 1.4
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <[email protected]>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version number
List
To lists the tags in alphabetical order
git tag
Github: for example for spark: https://api.github.com/repos/apache/spark/tags
Search
With a pattern
git tag -l "v1.8.5*"
v1.8.5
v1.8.5-rc0
Push
By default, the git push command doesn’t transfer tags to remote servers.
git push origin v1.5
where:
- origin. See What is the Origin in Git?
- v1.5 is the tag name
Delete
- Remote
git push --delete origin tagname
- Local
git tag --delete tagname
Checkout
Checkout Tag
Checkout is not a really checkout as they can't be modified
git checkout tags/tagName
# example
git checkout tags/release-1.4.0-rc1
where release-1.4.0-rc1 is the tag name
Checkout Tag with branch creation
git checkout tags/v2.0.0 -b version2
Switched to a new branch 'version2'
where:
- -b version2 gives to the branch the name version2
- v2.0.0 is the tag name
Documentation / Reference
- git-tag - Create, list, delete or verify a tag object signed with GPG