git diff
View the exact changes between commits, branches, or the working tree
Practical example
git diff # unstaged changes vs staging git diff --staged # staged vs last commit git diff main feature-login # compare two branches
Command overview & how it works
Compares different states in the repository and shows the line-by-line differences. Lines starting with + are additions (shown in green), lines starting with - are deletions (shown in red). By default, git diff compares the working directory against the staging area. Use git diff --staged (or --cached) to see what is staged versus the last commit. Use git diff <branch1> <branch2> to compare two branches, or git diff <commit1> <commit2> to compare specific commits. Add --stat for a summary of changed files and line counts, --name-only to show only file names, or --color-words for a word-level (instead of line-level) diff. For complex merges, git diff --ours, --theirs, and --base help identify conflicting changes during merge conflicts.
Master Git log, diff, and blame offline
Read advanced graph traversals, patch analysis, and investigation workflows in the 97-page offline course — ₹499.
Practical tips
- Run git diff --staged before committing to review exactly what is about to be recorded.
- Use git diff --stat for a quick summary of which files changed and by how many lines.
- For code reviews, git diff main...feature shows only the changes made on the feature branch since it diverged.
Deep-dive guides & tutorials
In-depth walkthroughs and practical scenarios related to git diff
- Tutorial
Git Log Formats: Customize Your History Output
Master git log with custom formats, filters, and graph views. Learn the format placeholders that turn raw history into a readable, useful log.
7 min readRead guide - Tutorial
Git Diff: Compare Changes Across Commits and Branches
See exactly what changed between commits, branches, or your working directory. Master git diff for thorough code reviews.
5 min readRead guide - Tutorial
Git Blame: Track Changes Back to Their Author
Use git blame to find who last modified every line of a file. Essential for code review, debugging, and understanding project history.
4 min readRead guide
Related commands
More from Working with Changes