Lesson Completion
Back to course

Searching by Tag

Beginner
7 minutes4.7Git

The Hook (The "Byte-Sized" Intro)

"When did this bug start?" is hard to answer with commit SHAs. But with tags, it becomes: "Was it working in v1.2.0?" Tags turn your history into versioned checkpoints. You can diff between releases, log changes between versions, and scope searches to specific release windows — all using human-readable names instead of SHA hashes.

📖 What is Searching by Tag?

Using Git tags as anchors to scope history searches, comparisons, and investigations to specific version ranges.

Conceptual Clarity

Tag-based search operations:

GoalCommand
Changes between releasesgit log v1.0..v2.0 --oneline
Diff between releasesgit diff v1.0..v2.0 --stat
Search code at a versiongit grep "term" v1.0
Blame at a versiongit blame v1.0 -- file.js
Bisect between versionsgit bisect start v2.0 v1.0
Find closest taggit describe
Files changed between tagsgit diff --name-only v1.0..v2.0

Real-Life Analogy

Tags are like chapter numbers in a book. Instead of saying "page 347," you say "Chapter 5." Instead of "commit abc123," you say "v1.2.0." It's the same content, but far easier to navigate and communicate.

Visual Architecture

flowchart LR V1["🏷️ v1.0.0"] -->|"git log v1.0..v2.0"| V2["🏷️ v2.0.0"] V1 -->|"git diff v1.0..v2.0"| V2 V1 -->|"git bisect start v2.0 v1.0"| V2 style V1 fill:#1a1a2e,stroke:#ffd700,color:#ffd700 style V2 fill:#0f3460,stroke:#53d8fb,color:#53d8fb

Why It Matters

  • Readability: v1.0..v2.0 is clearer than abc123..def456.
  • Release scoping: Investigate bugs within specific version ranges.
  • Historical search: git grep at any tagged version.
  • Communication: "It works in v1.2 but breaks in v1.3" is actionable.

Code

bash
# ─── What changed between releases? ─── git log v1.0.0..v2.0.0 --oneline # Lists all commits between the two releases # ─── Files changed between releases ─── git diff --name-only v1.0.0..v2.0.0 # ─── Search code at a specific version ─── git grep "validateToken" v1.0.0 # Searches the codebase as it was at v1.0.0 # ─── Blame at a specific version ─── git blame v1.0.0 -- src/auth.js # ─── What's the closest tag? ─── git describe # v1.2.0-5-gabc1234 # Meaning: 5 commits after v1.2.0, at commit abc1234 # ─── Bisect between tagged releases ─── git bisect start v2.0.0 v1.0.0 # v2.0.0 is bad, v1.0.0 is good

Key Takeaways

  • Tags provide human-readable anchors for history operations.
  • git log v1..v2, git diff v1..v2, git grep "x" v1 all work with tags.
  • git describe tells you the closest tag and distance from it.
  • Use tag ranges to scope investigations to specific release windows.

Interview Prep

  • Q: How do you find what changed between two releases? A: git log v1.0.0..v2.0.0 --oneline shows commits, git diff v1.0.0..v2.0.0 --stat shows file changes. Both use tags as human-readable anchors.

  • Q: What does git describe output mean? A: It outputs <tag>-<n>-g<sha>: the most recent reachable tag, number of commits since that tag, and the current commit's short SHA. For example, v1.2.0-5-gabc1234 means 5 commits after v1.2.0.

  • Q: How do you search for a string in a previous release? A: git grep "string" <tag>. This searches the codebase as it existed at that tagged version, without checking out the code.

Topics Covered

Git HistoryTags

Tags

#git#tags#search#history

Last Updated

2026-02-13