Terminal GuideTerminal Guide

git diff Command Guide

Show changes between commits, commit and working tree, etc

7 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

git diffWorking dir vs staged
git diff --stagedStaged vs last commit
git diff HEADWorking dir vs HEAD

Compare

git diff <branch>Compare with branch
git diff a..bBetween commits
git diff a...bCommon ancestor to b

Options

--statSummary statistics
--name-onlyFile names only
-wIgnore whitespace

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git diff command shows differences between various states of your repository - working directory, staging area, and commits.

bash
# Show unstaged changes
git diff

# Show staged changes (ready for commit)
git diff --staged
git diff --cached  # Same as --staged

# Show all changes (staged + unstaged)
git diff HEAD

Comparing Different States

bash
# Working directory vs staging area
git diff

# Staging area vs last commit
git diff --staged

# Working directory vs last commit
git diff HEAD

# Working directory vs specific commit
git diff abc1234

# Between two commits
git diff abc1234 def5678
git diff abc1234..def5678  # Same thing

# Specific file
git diff -- file.js
git diff HEAD -- file.js

Understanding Diff States

  • Working Directory: Your current file changes
  • Staging Area (Index): Changes added with git add
  • HEAD: Last commit on current branch

Common Options

OptionDescription
--statShow diffstat summary
--name-onlyShow only changed file names
--name-statusShow names and change status (A/M/D)
-w, --ignore-all-spaceIgnore all whitespace
--word-diffShow word-level diff
--color-wordsHighlight changed words in color

Diffing Branches

bash
# Changes between branches
git diff main..feature

# What's in feature that's not in main
git diff main...feature

# Compare with remote branch
git diff origin/main

# Before merging, see what would change
git diff HEAD...origin/main

# Compare specific file across branches
git diff main..feature -- src/app.js

Practical Examples

bash
# Review before committing
git diff --staged

# Quick summary of changes
git diff --stat

# See what files changed
git diff --name-only HEAD~3

# Ignore whitespace changes
git diff -w

# Word-level diff (useful for prose)
git diff --word-diff

# Compare with last week
git diff HEAD@{1.week.ago}

# Export diff as patch
git diff > changes.patch

# Check if there are changes
git diff --quiet || echo "Changes detected"

Frequently Asked Questions

What is the difference between git diff and git diff --staged?

"git diff" shows unstaged changes (working directory vs staging area). "git diff --staged" (or --cached) shows staged changes that will go into the next commit.

How do I see changes between two branches?

Use "git diff branch1..branch2" to see changes. "git diff main..feature" shows what feature has that main doesn't.

How do I diff a specific file?

Add the filename at the end: "git diff HEAD -- filename" or "git diff branch1..branch2 -- filename".

How do I ignore whitespace changes?

Use "git diff -w" or "--ignore-all-space". Use "-b" to ignore changes in amount of whitespace.

What does the diff output format mean?

Lines starting with - are removed, + are added. @@ shows the line numbers. The header shows the files being compared.

Summary

git diff is essential for reviewing changes before committing. Use --staged to see what's going into your next commit.

Quick Reference

  • git diff - Unstaged changes
  • git diff --staged - Staged changes
  • git diff HEAD - All changes
  • git diff branch1..branch2 - Between branches

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles