Lesson Completion
Back to course

Listing and Inspecting Tags

Beginner
7 minutes4.7Git

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:

GoalCommand
List all tagsgit tag
Filter by patterngit 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 messagesgit tag -n
Show with full messagesgit tag -n99

Inspecting commands:

GoalCommand
Full tag detailsgit show v1.0.0
Commit the tag points togit rev-parse v1.0.0
Diff between two tagsgit diff v1.0.0..v1.1.0
Commits between tagsgit 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

flowchart TD LIST["git tag -l"] --> FILTER["Pattern: v1.*"] LIST --> SORT["Sort: version or date"] LIST --> SHOW["git show tag"] SHOW --> META["Tagger, date, message"] SHOW --> DIFF["git diff tag1..tag2"] style LIST fill:#0f3460,stroke:#53d8fb,color:#53d8fb style SHOW fill:#1a1a2e,stroke:#ffd700,color:#ffd700

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 -l to find latest releases.
  • Sorting: Version-aware sorting prevents v10 appearing before v2.

Code

bash
# ─── 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 releases

Key Takeaways

  • git tag lists all tags; -l "pattern" filters them.
  • Use --sort=version:refname for correct SemVer ordering.
  • git show <tag> reveals full tag metadata and the tagged commit.
  • git log tag1..tag2 shows 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 --oneline shows all commits between the tags. git diff v1.0.0..v1.1.0 --stat shows 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.0 before v2.0.0. Using --sort=version:refname applies semantic version ordering where v2.0.0 correctly appears before v10.0.0.

  • Q: How do you find the latest tag in a repository? A: git describe --tags --abbrev=0 returns the most recent tag reachable from HEAD. Alternatively, git tag -l --sort=-version:refname | head -1 lists tags sorted newest-first.

Topics Covered

Git TagsGit Fundamentals

Tags

#git#tags#list#beginner-friendly

Last Updated

2026-02-13