How to compare two tags with git?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Git tags are usually used to mark releases or other important points in history. Comparing two tags is really just comparing the commits they point to, and Git gives you several ways to do that depending on whether you care about file content, commit history, or just a quick summary.
The Most Common Comparison Commands
If you want to see the code differences between two tags, use git diff:
Those commands answer slightly different questions:
- plain
git diffshows the actual line-by-line patch - '
--statshows file counts and insertion-deletion totals' - '
--name-statusshows which files changed and whether they were added, modified, or deleted'
If you care about the commits that happened between the two releases, use git log instead:
The two-dot range means "commits reachable from v1.3.0 that are not reachable from v1.2.0". That is often exactly what you want for release notes.
Comparing One File or One Tag Object
Sometimes you do not want the whole release diff. You want to inspect a single file across tags.
That is especially useful when one release contains a large amount of unrelated churn but you only care about one module.
Annotated tags and lightweight tags can both be compared this way because Git resolves both tags to commits before running the diff. The comparison behavior is about the target commits, not the tag metadata.
Make Sure the Tags Exist Locally
A surprising number of comparison problems come from stale local tags. If the repository was cloned without tags, or if newer release tags were created on the remote after your last fetch, update them first.
Once the tags are present locally, the comparison commands work exactly the same as branch or commit comparisons.
Choosing the Right View
Pick the command based on the question you are asking:
- use
git diffwhen you want to review code changes - use
git log old..newwhen you want the commit list between releases - use
git diff --statfor a lightweight summary - use
git show tag:pathwhen you want one file at one release point
If you need a merge-aware review, git range-diff can also be useful, but that is usually for comparing patch series rather than simple release tags.
Common Pitfalls
- Forgetting
git fetch --tagsand then comparing outdated local tag data. - Reversing the tag order.
git diff old newanswers a different question fromgit diff new oldbecause additions and deletions flip direction. - Using
git log tag1 tag2when you actually wantedgit log tag1..tag2. - Assuming annotated tags compare differently from lightweight tags. In normal diff and log commands, both resolve to the commits they reference.
- Comparing tags in a shallow clone that does not contain enough history.
Summary
- Comparing two tags in Git usually means comparing the commits those tags point to.
- '
git diff tag1 tag2shows code changes, whilegit log tag1..tag2shows the commit history between them.' - '
--statand--name-statusare useful summary forms of the diff.' - Fetch tags first if you are not sure the local repository is up to date.
- Use file-specific comparisons when the full release diff is too noisy.

