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.
Comparing 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
AI Model Comparison
Compare GPT, Claude, Gemini, Llama, and more — pricing, context windows, capabilities, and reasoning support for 21 models
JSON Visualizer
Visualize JSON as an interactive tree — collapsible nodes, search, path copy, depth controls, and data statistics
Compression Tester
Test and compare Brotli, Gzip, and Deflate compression ratios for text content — sizes, savings, and speed
TypeScript 6.0 Migration Checker
Analyze your tsconfig.json for TS 6.0 breaking changes, deprecated options, new defaults, and get a readiness grade with fixes