| name | diff-preview |
| description | Preview and analyze git diffs with AI explanations. Use to understand changes before committing, get impact analysis, and compare branches or commits. |
Diff Preview & Analysis
Preview, explain, and analyze git changes with AI assistance.
Prerequisites
git --version
pip install google-generativeai
export GEMINI_API_KEY=your_api_key
CLI Reference
Basic Diff Commands
git diff
git diff --staged
git diff --cached
git diff path/to/file.ts
git diff abc123 def456
git diff main feature-branch
git diff main...feature-branch
git diff --stat
git diff --shortstat
git diff --name-only
git diff --name-status
Diff Output Options
git diff --word-diff
git diff --color-words
git diff -w
git diff --ignore-all-space
git diff -U10
git diff --function-context
Commit Comparison
git diff HEAD~1
git diff HEAD~5
git diff abc123..def456
git show abc123
AI-Powered Analysis
Explain Changes
DIFF=$(git diff --staged)
gemini -m pro -o text -e "" "Explain these code changes in plain English:
$DIFF
Summarize:
1. What was changed
2. Why it might have been changed
3. Any potential issues"
Impact Analysis
DIFF=$(git diff main...feature-branch)
gemini -m pro -o text -e "" "Analyze the impact of these changes:
$DIFF
Consider:
1. Breaking changes
2. Performance implications
3. Security considerations
4. Files/systems affected
5. Testing recommendations"
Pre-Commit Review
git diff --staged | gemini -m pro -o text -e "" "Review this code diff for:
1. Bugs or issues
2. Code style problems
3. Missing error handling
4. Security concerns
Provide specific line references if issues found."
Generate Commit Message
DIFF=$(git diff --staged)
gemini -m pro -o text -e "" "Based on this diff, suggest a commit message:
$DIFF
Use conventional commit format (feat/fix/chore/etc).
First line under 50 chars, then details."
Comparison Patterns
Compare Branches
git diff main feature-branch --stat
git diff main feature-branch
git diff main...feature-branch
git log main..feature-branch --oneline
Find What Changed
git diff --name-only abc123 def456
git log -p -- path/to/file.ts
git blame path/to/file.ts
Merge Preview
git merge --no-commit --no-ff feature-branch
git diff --staged
git merge --abort
Workflow Patterns
Pre-Commit Check
#!/bin/bash
echo "=== Changes to commit ==="
git diff --staged --stat
echo ""
echo "=== Detailed diff ==="
git diff --staged
echo ""
read -p "Proceed with commit? (y/n) " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
git commit
fi
PR Review Prep
BASE=${1:-main}
BRANCH=$(git branch --show-current)
echo "=== Files changed ==="
git diff $BASE...$BRANCH --name-status
echo ""
echo "=== Stats ==="
git diff $BASE...$BRANCH --shortstat
echo ""
echo "=== AI Summary ==="
git diff $BASE...$BRANCH | gemini -m pro -o text -e "" "Summarize this PR's changes for a code reviewer. Focus on the intent and key changes."
Track Specific Changes
git log -p -S "functionName" -- "*.ts"
git log -p --grep="JIRA-123"
Best Practices
- Review before commit - Always check
git diff --staged
- Use stat first - Get overview before full diff
- Compare with base - Use
main...branch for PR context
- Ignore whitespace - Use
-w for meaningful changes
- Request AI review - For complex changes
- Save important diffs - Redirect to file for reference