🔍 See What You Changed Before Committing
Forgot what you changed? git diff shows unstaged changes. Review before commit. Prevent accidental commits.
📝 Diff Commands
# Unstaged changes git diff # Staged changes (added but not committed) git diff --staged git diff --cached # Between two commits git diff commit1 commit2 # Specific file git diff src/app.js # Word diff (better for text) git diff --word-diff # Show only file names git diff --name-only # Ignore whitespace git diff --ignore-space-change
🎯 Visual Diff Tools
# Open visual diff tool (if configured) git difftool # Configure diff tool git config --global diff.tool vscode git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE' # VS Code as difftool git config --global diff.tool vscode git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE' # See changes from last commit git diff HEAD~1 # Compare branches git diff main..feature
💡 Best Practice
- Always git diff before commit
- Review staged changes with git diff –staged
- Catches accidental debug code
- Prevents committing secrets
- Ensures you know what you’re committing
“Committed console.log by accident. Now always git diff before commit. Caught many accidental changes since. Essential habit.”
