Show diff between commits
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Showing diffs between commits in Git is a core workflow for code review, debugging regressions, and release auditing. While git diff syntax is straightforward, choosing the right range and output format matters for accurate analysis. Developers often compare the wrong endpoints or miss rename/move context, leading to incorrect conclusions about what changed.
Core Sections
Basic commit-to-commit diff
Use commit hashes directly.
This shows changes needed to go from old to new snapshot.
Useful options
Limit noise and improve readability:
-M helps detect renames; -w ignores whitespace-only changes.
Compare ranges with two-dot and three-dot
A..Boften used in log-style commit ranges.A...Bfor diff comparesmerge-base(A,B)toB, useful for branch review.
This is common in pull-request preparation.
Diff specific file between commits
Great for targeted investigations in large repositories.
Visual and external tools
You can use git difftool or IDE integrations for side-by-side analysis when line-level context is complex.
Common Pitfalls
- Comparing the wrong commit order and misreading added vs removed lines.
- Confusing log range semantics with diff endpoint semantics.
- Ignoring rename detection and treating moved files as full delete/add.
- Reviewing huge diffs without narrowing to relevant paths first.
- Using whitespace-sensitive diffs for formatting-only commits.
Implementation Playbook
To make this topic production-ready, treat implementation as a repeatable workflow instead of a one-time fix. Start by defining an explicit baseline with known inputs, expected outputs, and measured runtime behavior. Baselines are critical because many regressions appear only after dependency upgrades, environment changes, or infrastructure shifts that do not modify application code directly. A baseline lets you detect drift quickly and determine whether a failure came from logic changes, runtime configuration, or platform behavior.
Next, design a small but representative validation matrix that covers happy-path, edge-case, and failure-path scenarios. Keep the matrix lightweight enough to run frequently, ideally in local development and CI, and strict enough to catch common integration mistakes. If this topic depends on external services, include deterministic stubs or contract fixtures so tests remain stable and actionable. For observability, log key identifiers, decision branches, and outcome statuses in a structured format; this allows fast correlation in dashboards and incident timelines without manual guesswork.
After correctness checks, add operational safeguards. Define timeout behavior, retry policy, and rollback triggers before rollout. Avoid making multiple high-risk changes simultaneously; apply one change, verify, then continue. Incremental rollout minimizes blast radius and produces clearer diagnostics when behavior diverges from expectations. In shared systems, publish a short runbook that lists prerequisites, expected metrics, and first-response troubleshooting steps. This documentation prevents repeated rediscovery work and improves handoff quality across teams.
Use the following execution checklist for consistent delivery:
Change Control Note
Apply updates in small increments and verify each increment with one deterministic test run before proceeding. Incremental changes reduce rollback scope and make root-cause analysis faster if behavior shifts after dependency or configuration changes.
Summary
git diff between commits is simple but requires correct endpoint selection and options. Use range forms intentionally, narrow by path when needed, and enable rename/whitespace options for cleaner reviews. This produces faster and more accurate change analysis.
Related reading
- Show full Git commit message in console without having to resize the window
- Show git diff on file in staging area
- Show git diff on file in staging area
- Show just the current branch in Git
- Show SSH key file in Git Bash
- Show which git tag you are on?
- Showing which files have changed between two revisions
- Simple tool to 'accept theirs' or 'accept mine' on a whole file using git
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.