Git Diff Command Guide
Master the git diff command with practical examples. Generate diff output and paste it into the viewer above to see it rendered with syntax highlighting and line numbers.
Git Diff Viewer
Paste unified diff output (from git diff) and view it with syntax highlighting, line numbers, and side-by-side or inline display.
Paste a unified diff above to render it with syntax highlighting and line numbers.
Basic git diff usage
Running 'git diff' with no arguments shows unstaged changes in your working directory compared to the index (staging area). Use 'git diff --staged' (or --cached) to see changes that are staged for the next commit. Use 'git diff HEAD' to see all changes (staged and unstaged) compared to the last commit.
# Essential git diff commands
# Unstaged changes (working directory vs index)
git diff
# Staged changes (index vs last commit)
git diff --staged
# Between two commits
git diff abc123 def456
# Between branches
git diff main..feature-branch
# Specific file only
git diff -- src/app.ts
# Show only file names changed
git diff --name-only
# Show stats (insertions/deletions per file)
git diff --stat
# Word-level diff (instead of line-level)
git diff --word-diff
# Ignore whitespace changes
git diff -wComparing branches and commits
Compare two branches: 'git diff main..feature-branch'. Compare a specific commit to HEAD: 'git diff abc1234..HEAD'. Show changes introduced by a single commit: 'git diff abc1234^..abc1234' or simply 'git show abc1234'. Compare specific files: 'git diff main -- src/app.ts'. Use 'git diff --stat' for a summary of changed files without full content.
Useful git diff flags
Common flags include: --stat (file change summary), --name-only (list changed file names), --name-status (names with A/M/D status), --word-diff (word-level differences), --color-words (inline word-level coloring), -U5 (show 5 context lines instead of default 3), --ignore-space-change (-b, ignore whitespace changes), and --diff-filter=M (show only modified files).
Frequently Asked Questions
How do I see what changed in the last commit?
Use 'git diff HEAD~1..HEAD' to compare the last commit with the one before it. Alternatively, 'git show' displays the diff for the most recent commit along with its commit message. For a specific commit, use 'git show <commit-hash>'.
How do I generate a patch file from git diff?
Run 'git diff > changes.patch' to save the diff to a file. Apply it later with 'git apply changes.patch'. For commits, use 'git format-patch -1 HEAD' to create a patch file with commit metadata. Patches can be shared via email or file transfer and applied with 'git am'.
Related Inspect Tools
GitHub Actions Validator
Validate GitHub Actions workflow YAML files for syntax, triggers, job structure, step config, needs dependencies, and deprecated actions
Aspect Ratio Calculator
Calculate aspect ratios from any dimensions, resize while preserving proportions, and find equivalent sizes. Device presets for phones, tablets, monitors, and social media
XPath Tester
Test XPath expressions against XML data with real-time evaluation — select elements, filter by attributes, navigate axes, and use XPath functions
SQL Playground
Run SQL queries in your browser with a full SQLite database powered by WebAssembly — practice JOINs, CTEs, window functions, aggregations, and more