DevBolt
Processed in your browser. Your data never leaves your device.

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.

← Back to tools

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.

Ctrl+Enter to parse
Samples:

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