git tag, git tag -a -m, git cat-file -t
git tag <tagname>
git tag -a <tagname> -m <message>
git tag -l
git cat-file -t <tagname>Create a lightweight or annotated tag at HEAD, list tags, and report the object type.
| Parameter | Description |
|---|---|
<tagname> | The tag name. Lightweight tags store no separate message. |
-a / --annotate | Create an annotated tag object. Combine it with -m, or Git will open an editor for the message. |
-m <message> | The annotation stored on the tag object. |
Returns: A new tag ref. For -a, a tag object is also written and the ref points at that object.
- Signed tags (-s, -u) are not covered here and are not created in the example. They would require a signing key.
git init -b main >/dev/null
git config user.name "Practice Author"
git config user.email "[email protected]"
git config commit.gpgsign false
git config color.ui false
mkdir -p .disabled-hooks
git config core.hooksPath ".disabled-hooks"
printf 'base\n' > file.txt
git add file.txt
git commit -m "Add file" >/dev/null
git tag v1.0.0
git tag -a v1.1.0 -m "Release 1.1.0"
echo "list"
git tag -l
echo "v1.0.0-type=$(git cat-file -t v1.0.0)"
echo "v1.1.0-type=$(git cat-file -t v1.1.0)"
echo "show-light"
git show --no-patch --pretty=format:%h%x20%s v1.0.0
echo
echo "show-annot"
git show --no-patch --pretty=medium v1.1.0
Expected output
list
v1.0.0
v1.1.0
v1.0.0-type=commit
v1.1.0-type=tag
show-light
8bb07df Add file
show-annot
tag v1.1.0
Tagger: Practice Author <[email protected]>
Date: Mon Jan 15 12:00:00 2024 +0000
Release 1.1.0
commit 8bb07df53f0f824d66b045c6ee66dab277c9350d
Author: Practice Author <[email protected]>
Date: Mon Jan 15 12:00:00 2024 +0000
Add file
Related: git show