The Hook (The "Byte-Sized" Intro)
A repo with 500 tags and no way to search them is like a library with no catalog. You need to list them, filter by pattern, sort by version, and inspect what a tag contains. Git gives you all these tools — you just need to know the flags.
📖 What is Listing and Inspecting Tags?
This lesson covers how to list all tags, filter them by pattern, sort them by version, and inspect a tag's full details.
Conceptual Clarity
Listing commands:
| Goal | Command |
|---|---|
| List all tags | git tag |
| Filter by pattern | git tag -l "v1.*" |
| Sort by version (SemVer) | git tag -l --sort=version:refname |
| Sort by date (newest first) | git tag -l --sort=-creatordate |
| Show with commit messages | git tag -n |
| Show with full messages | git tag -n99 |
Inspecting commands:
| Goal | Command |
|---|---|
| Full tag details | git show v1.0.0 |
| Commit the tag points to | git rev-parse v1.0.0 |
| Diff between two tags | git diff v1.0.0..v1.1.0 |
| Commits between tags | git log v1.0.0..v1.1.0 --oneline |
Real-Life Analogy
Listing tags is like browsing a bookshelf by spine labels. Inspecting a tag is like pulling the book off the shelf and reading the preface to understand what's inside.
Visual Architecture
Why It Matters
- Release tracking: Quickly find what version is deployed.
- Debugging: Diff between tags to find what changed between releases.
- Automation: Scripts use
git tag -lto find latest releases. - Sorting: Version-aware sorting prevents
v10appearing beforev2.
Code
# ─── List all tags ───
git tag
# v0.9.0
# v1.0.0
# v1.1.0
# ─── Filter by pattern ───
git tag -l "v1.*"
# v1.0.0
# v1.1.0
# ─── Sort by SemVer (correct order) ───
git tag -l --sort=version:refname
# v0.9.0, v1.0.0, v1.1.0, v2.0.0 (correct!)
# Without sort: v1.0.0, v10.0.0, v2.0.0 (wrong!)
# ─── Show tag messages alongside names ───
git tag -n
# v1.0.0 First stable release
# v1.1.0 Added search feature
# ─── Inspect a specific tag ───
git show v1.0.0
# Shows: tagger, date, message, then the commit
# ─── What changed between two releases? ───
git log v1.0.0..v1.1.0 --oneline
# Shows all commits between v1.0.0 and v1.1.0
git diff v1.0.0..v1.1.0 --stat
# Shows files changed between releasesKey Takeaways
git taglists all tags;-l "pattern"filters them.- Use
--sort=version:refnamefor correct SemVer ordering. git show <tag>reveals full tag metadata and the tagged commit.git log tag1..tag2shows commits between two releases — essential for debugging.
Interview Prep
-
Q: How do you find what changed between two releases? A:
git log v1.0.0..v1.1.0 --onelineshows all commits between the tags.git diff v1.0.0..v1.1.0 --statshows the files changed. You can combine these to generate release notes. -
Q: Why is version-aware sorting important for tags? A: Default alphabetical sorting puts
v10.0.0beforev2.0.0. Using--sort=version:refnameapplies semantic version ordering wherev2.0.0correctly appears beforev10.0.0. -
Q: How do you find the latest tag in a repository? A:
git describe --tags --abbrev=0returns the most recent tag reachable from HEAD. Alternatively,git tag -l --sort=-version:refname | head -1lists tags sorted newest-first.