Git has the ability to tag specific points in a repository’s history. This is useful to mark releases (like v1.2 or v2.0).
What you will learn?
- Types of git tags and how to create them?
- List existing git tags.
- How to delete a git tag?
- How to move the last tag to the latest commit?
- How to edit a tag message?
- How to get the code from a specific tag?
Types of git tags and how to create them?
There are two types of git tags: lightweight and annotated.
Most of the time you will use Annotated tags. A Lightweight tag is mostly used for private purposes.
Annotated Tags
This stores information such as tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG).
git tag -a v1.9 -m "your release information..." -s
# -a = annotated
# -m = message
# -s = signed
# Use this to list detailed information that the tag stores.
git show v1.9
Lightweight Tags
Do not use -a
, -s
, or -m
to apply lightweight tag, just provide a tag name.
git tag v1.9
# Use this to list detailed information that the tag stores.
git show v1.9
List existing git tags.
git tag
This command lists tag in alphabetical order.
# Output
v1.0
v1.1
v1.2
You can also search for tags that match a particular pattern.
git tag -l "v1.8*"
# Output
v1.8
v1.8-rc0
v1.8-rc1
v1.8-rc2
v1.8-rc3
How to delete a git tag?
git tag -d v1.8
# -d = delete
How to move the last tag to the latest commit?
git tag -f -a <tag_name>
git push -f --tags
How to edit a tag message?
git tag -m '<edited_message>' --edit <tag_name> -s -f
How to get the code from a specific tag?
You can checkout a tag and create a new branch from it.
git checkout -b <new_branch_name> <tag_name>
Top comments (0)