Check Change Files in Git
You can compare only the files that differ between your current local branch and another branch on the remote using Git. Here are the most common and useful ways, from simplest to more detailed.
1. List only the changed files (most common)
git fetch origin
git diff --name-only origin/other-branch
If you want to be explicit about your current branch:
git diff --name-only origin/other-branch..HEAD
➡️ Shows only file paths that are different.
2. List changed files with change type (added / modified / deleted)
git diff --name-status origin/other-branch..HEAD
Example output:
M src/app.js
A src/new-file.ts
D src/old-file.css
3. Compare against the common ancestor (recommended for PR-style comparison)
This avoids noise from changes made in the target branch after you branched.
git diff --name-only origin/other-branch...HEAD
...(three dots) means:
changes on your branch since it diverged from the other branch
This is usually what you want when preparing a PR.
4. Show actual diffs for only changed files
git diff origin/other-branch...HEAD
Or for a single file:
git diff origin/other-branch...HEAD -- path/to/file
5. If you want only committed changes (no working tree changes)
git diff --name-only origin/other-branch...HEAD
If you want to include uncommitted changes too:
git diff --name-only origin/other-branch...HEAD
git diff --name-only --cached
Quick cheat sheet
| Goal | Command |
|---|---|
| File list only | git diff --name-only origin/branch...HEAD |
| File list + status | git diff --name-status origin/branch...HEAD |
| Full diff | git diff origin/branch...HEAD |
| Against exact branch state | git diff origin/branch..HEAD |
Total page views:
Comments
Post a Comment