bashbeginner
Git Diff — Word, Stat, and Patch Options
Advanced diff techniques: word-level diff, stat summary, diff between branches, and patch creation.
bashPress ⌘/Ctrl + Shift + C to copy
# Diff of unstaged changes
git diff
# Diff of staged changes
git diff --staged # or --cached
# Word-level diff (great for prose/docs)
git diff --word-diff
# Color words inline
git diff --color-words
# Stat summary (files changed, lines added/removed)
git diff --stat
# Name-only (just list changed files)
git diff --name-only
git diff --name-status # with A/M/D status
# Diff between branches
git diff main..feature/auth
git diff main..feature/auth -- src/ # specific directory
# Diff between commits
git diff abc1234..def5678
# Diff ignoring whitespace
git diff -w
git diff --ignore-space-change
# Show diff for a single file
git diff -- src/auth.ts
# Create a patch file
git diff > my-changes.patch
git diff --cached > staged-changes.patch
# Apply a patch
git apply my-changes.patch
git apply --check my-changes.patch # dry run
# Diff with external tool
git difftool main..feature/authUse Cases
- Reviewing changes before committing
- Comparing feature branches against main
- Creating and applying patches for code review
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
bashintermediate
Advanced Git Diff Techniques
Compare changes between branches, commits, and working tree with filtering and formatting options.
Best for: Reviewing changes before code review
#git#diff
bashintermediate
Git Hooks Pre Commit
Git workflow: git-hooks-pre-commit
Best for: version control
#git#version-control
bashadvanced
Git Hooks Post Commit
Git workflow: git-hooks-post-commit
Best for: version control
#git#version-control
bashadvanced
Git Lfs Large Files
Git workflow: git-lfs-large-files
Best for: version control
#git#version-control