Git Tags: Lightweight and Annotated Tags
Give a commit a memorable name
A tag is a named reference, often used to identify a release commit. Unlike a checked-out branch, a tag does not advance when you commit. Start in the disposable tags lab, at the initial commit on main. The first command creates a lightweight tag; the second displays tag names.
The list includes checkpoint. Creating it leaves the working files, index and current branch unchanged.
Record release metadata
An annotated tag points to a separate tag object containing the target, tagger, date and message. A lightweight tag directly references an object (a commit in this example). Use the same initial commit. The type inspection commands are read-only; cat-file is introduced here only to distinguish object types.
git tag -a v1.0.0 -m "First stable release"git cat-file -t checkpointgit cat-file -t v1.0.0git show --no-patch v1.0.0The two type queries print commit and tag respectively. The show output includes the tag message and commit information. An annotated tag is not necessarily signed.
Advance the branch, not the tag
Continue in the same lab. Change the note and commit it. The revision syntax ^{commit} resolves a tag to its underlying commit, including through an annotated tag object. Git tags are technically movable, but treating published release tags as fixed avoids confusing consumers.
printf "Tea and milk\n" > notes.txtgit add -- notes.txtgit commit -m "Expand notes"git rev-parse HEADgit rev-parse "v1.0.0^{commit}"git show v1.0.0:notes.txtThe IDs differ; the historical file still contains Tea. Practice: create a second lightweight tag at the new commit and check that the first tag stays at the earlier commit.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Tags: Lightweight and Annotated Tags — knowledge check
Reason about release markers, tag transfer and version naming.
What moves when a new commit is made on main?
Which object type does cat-file -t report for an annotated tag?
What information distinguishes an annotated tag?
How can you inspect a file at an earlier release without switching?
Does an annotated tag necessarily contain a signature?