How to view differences in Git
· Category: Git
Short answer
Use git diff to see changes between your working directory, staging area, and commits.
Steps
- View unstaged changes:
git diff
- View staged changes:
git diff --staged
- Compare two commits:
git diff abc1234 def5678
- Compare a specific file across branches:
git diff main..feature -- file.txt
Tips
git diff --statshows a summary of changed files.- Use
--word-difffor prose documents to see word-level changes. - Redirect output to a file:
git diff > changes.patch.
Common issues
- No output after staging: remember
--stagedis required for staged changes. - Binary files: diffing binaries is not useful; use external diff tools for images.