Showing which files have changed between two revisions
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When you only want to know which files changed between two revisions, the best command is usually a name-only diff rather than a full content diff. Most version-control tools support this directly. In Git, the standard answer is git diff --name-only rev1 rev2. Other systems such as Subversion and Mercurial provide similar flags or workflows.
Git: List Changed Files Only
For Git, the most direct command is:
Example:
That prints only the file paths that differ between the two revisions.
If you also want to know whether a file was added, modified, or deleted, use --name-status instead.
Typical output includes markers such as A, M, and D.
Git: Summary Output
Sometimes a summary is more useful than a bare list.
This shows changed files plus insertion and deletion counts. It is still much shorter than a full patch and works well in reviews or release notes.
Subversion and Mercurial Equivalents
In Subversion, compare two revisions with svn diff.
That shows content changes. To focus on filenames, many teams pipe or parse the summary output instead:
In Mercurial, the equivalent diff uses revision flags:
And for just the file names:
The exact output format differs, but the idea is the same: compare two snapshots and ask for changed paths rather than full hunks.
Choose Revisions Carefully
A frequent source of confusion is comparing the wrong pair of revisions. In Git, these common patterns matter:
- '
A Bcompares the two snapshots directly' - '
A..Bis mostly a log-range concept, not the usual diff form' - '
A...Bcompares against the merge base, which answers a different question'
If you want “what files differ between commit A and commit B,” use the two explicit revisions with git diff.
Working Tree vs Revision Comparisons
Do not mix commit-to-commit comparisons with working-tree comparisons. git diff HEAD tells you what changed since the last commit in your current checkout. git diff rev1 rev2 tells you what changed between two recorded revisions.
Those are different tasks and often get confused when debugging a release or backport.
Use Script-Friendly Output When Automating Reports
If another tool needs the changed file list, prefer machine-friendly output such as --name-only or --name-status instead of parsing full patch text. That keeps release tooling simpler and avoids fragile text processing.
It also makes review automation more reliable because filenames and status codes are easier to consume than patch hunks.
Common Pitfalls
- Running a full diff when only filenames were needed.
- Using the wrong revision range syntax in Git.
- Comparing the working tree instead of two committed revisions.
- Forgetting
--name-statuswhen the change type matters. - Assuming every version-control system uses the same revision syntax and output style.
Summary
- In Git, use
git diff --name-only REVISION_A REVISION_Bto list changed files. - Use
--name-statuswhen you need added, modified, or deleted markers. - Use summary-style options in SVN and Mercurial for the same high-level view.
- Be precise about which revisions you are comparing.
- Separate commit-to-commit questions from working-tree questions.
Related reading
- Simple tool to 'accept theirs' or 'accept mine' on a whole file using git
- Simulating 2 phase distributed commit failures using grpc
- Skip Git commit hooks
- Skip Git commit hooks
- sorting a doubly linked list with merge sort
- space complexity of merge sort using array
- Specify an SSH key for git push for a given domain
- Spring - Multiple Spring Data modules found, entering strict repository configuration mode
.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.