Quick Answer

# Diff between working tree and staging area
git diff

# Diff of staged changes (before committing)
git diff --staged

# Compare two specific commits
git diff <commit1> <commit2>

What You’re Trying to Do

Before committing, you want to see exactly what changed. git status only lists filenames — to see line-by-line changes you need git diff.

It’s also common to get confused about the difference between staged and unstaged changes when using git diff.


Environment

  • Git 2.30 or later
  • OS: Linux / macOS / Windows (including WSL2)

Solution

Basic: View Changes in the Working Tree

git diff

This shows the difference between the last staged state (git add) and your current working tree. Use it to review changes before staging them.

View Staged Changes (—staged / —cached)

git diff --staged
# or
git diff --cached

After running git add, use this to confirm exactly what will be included in your next commit.

Diff a Specific File

git diff src/app.js

# multiple files
git diff src/app.js src/index.js

Compare Commits

# Diff against the previous commit
git diff HEAD~1 HEAD

# Diff between two specific commits
git diff a1b2c3d e4f5g6h

Compare Branches

# Diff current branch against main
git diff main

# Diff feature branch against main
git diff main..feature/login

Show a Summary of Changes (—stat)

git diff --stat

Example output:

 src/app.js   | 12 +++++++-----
 src/index.js |  4 ++--
 2 files changed, 10 insertions(+), 6 deletions(-)

Handy for getting a quick overview of which files changed before diving into details.

Word-Level Diff (—word-diff)

git diff --word-diff

Highlights only the changed words instead of whole lines — useful for reviewing prose files like Markdown.

Diff Against a Remote Branch

git fetch origin
git diff origin/main

You need to git fetch first, otherwise you’ll be comparing against a stale copy of the remote branch.


Common Errors

git diff Shows Nothing

git diff
# (no output)

If you’ve already run git add, git diff returns nothing because there’s no difference between the staged snapshot and the working tree. Check the staged changes instead:

git diff --staged

Binary Files Only Show Binary files differ

Binary files a/image.png and b/image.png differ

Git can’t produce a meaningful text diff for binary files like images or compiled artifacts. The --text flag forces a text diff, but the output is usually unreadable.

Diff Is Full of Line-Ending (CRLF/LF) Changes

Common in mixed Windows / Linux-macOS environments.

git config core.autocrlf input   # Linux/macOS
git config core.autocrlf true    # Windows

Setting this normalizes line endings going forward.

The Pager Opens and Is Hard to Navigate

By default, git diff output is piped through a pager like less.

# Print straight to stdout without a pager
git --no-pager diff

# Disable the pager permanently
git config --global core.pager cat

FAQ

Q: What’s the difference between git diff and git status? git status only lists which files changed. git diff shows the actual line-by-line content changes.

Q: How do I see both staged and unstaged changes together? Compare HEAD directly against the working tree to see everything at once.

git diff HEAD

Q: Can I view only added lines or only removed lines? In the diff output, - marks removed lines and + marks added lines. You can filter with grep:

git diff | grep "^-"

Q: Can I limit the diff to a specific directory? Yes, pass a path to scope the diff to that directory.

git diff src/components/

Q: Can I view diffs in a nicer external tool? Configure difftool to open diffs in an editor like VSCode.

git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
git difftool

Build your production environment on a reliable VPS: