A Python utility for generating comprehensive Git diff reports optimized for AI code review workflows. This tool helps you prepare code changes for AI review by creating structured, readable reports of Git changes.
# Install from PyPI
pip install git-diff-helper
# Show unstaged changes (default)
git-diff-helper
# Show all changes (staged, unstaged, and untracked)
git-diff-helper --all-changes
# Show only staged changes
git-diff-helper --staged-only
# Show only untracked files
git-diff-helper --untracked-only
- Generates three detailed reports:
- Complete diffs in a unified format
- Original file contents from HEAD
- Updated file contents from working directory
- Shows changes in different scopes:
- Unstaged, tracked changes (what you're working on)
- Untracked files (new files not tracked in Git)
- Staged changes (what you're about to commit)
- All changes (Untracked + Unstaged + Staged)
- Supports customizable file extension filtering
- Handles binary files and gitignored files appropriately
- Provides verbose logging option
- Configurable output directory
pip install git-diff-helper
pip install git+https://github.com/mlusas/git-diff-helper.git
git clone https://github.com/mlusas/git-diff-helper.git
cd git-diff-helper
pip install -e .
Basic usage shows unstaged changes (your work in progress):
git-diff-helper
Common workflows:
# Show everything (staged, unstaged, and untracked)
git-diff-helper --all-changes
# Show only staged changes (what you're about to commit)
git-diff-helper --staged-only
# Show only untracked files (new files)
git-diff-helper --untracked-only
# Filter by file extensions and output directory
git-diff-helper --extensions ".py,.js,.ts" --output-dir ./diffs
File Selection (mutually exclusive):
- Default: Show unstaged, tracked changes (work in progress)
--all-changes
,-a
: Show everything (staged, unstaged, and untracked)--staged-only
,-s
: Show only staged changes--untracked-only
,-u
: Show only untracked files
Output Options:
--output-dir
,-o
: Directory to save output files (default: current directory)--extensions
: Comma-separated list of file extensions to process (e.g., '.py,.js,.ts')--verbose
,-v
: Enable verbose logging
The tool generates three Markdown files:
diff_file_diffs.md
: Contains the actual diffs showing what changeddiff_file_originals.md
: Contains the original content of changed filesdiff_file_updated.md
: Contains the current content of changed files
- Generate diff reports:
# For a comprehensive review of everything
git-diff-helper --all-changes --output-dir ./review
# For reviewing what you're about to commit
git-diff-helper --staged-only --output-dir ./review
# For reviewing work in progress
git-diff-helper --output-dir ./review
-
Share the generated files with the AI:
diff_file_diffs.md
for a quick overview of changesdiff_file_originals.md
anddiff_file_updated.md
for deeper context- Use the AI's context window efficiently by sharing only relevant parts
-
Suggested prompts for AI review:
- "Please review these changes for potential bugs and improvements"
- "What are the security implications of these changes?"
- "How could this code be made more maintainable?"
- "Suggest optimizations for performance"
- Generate focused diffs for specific files:
# Review all Python changes
git-diff-helper --all-changes --extensions ".py"
# Review staged JavaScript changes
git-diff-helper --staged-only --extensions ".js"
- Open the diff files alongside your code
- Use Copilot suggestions while reviewing the changes
You can import and use the GitDiffHelper
class in your own Python scripts:
from git_diff_helper import GitDiffHelper
# Initialize with custom settings
helper = GitDiffHelper(
allowed_extensions={'.py', '.js'},
output_dir='./reports',
verbose=True
)
# Generate reports with different scopes
helper.generate_reports(scope='all') # Show everything
helper.generate_reports(scope='staged') # Show staged changes
helper.generate_reports(scope='unstaged') # Show unstaged changes
helper.generate_reports(scope='untracked') # Show untracked files
# Or use individual methods
changed_files = helper.get_changed_files(scope='all')
for file in changed_files:
diff = helper.get_file_diff(file, scope='all')
print(f"Changes in {file}:\n{diff}")
Pre-commit hook:
# .git/hooks/pre-commit
git-diff-helper --staged-only --output-dir ./review
git add ./review/*.md
CI/CD pipeline:
# In your CI/CD config
git-diff-helper --all-changes --output-dir $CI_PROJECT_DIR/code-review
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
# Clone the repository
git clone https://github.com/mlusas/git-diff-helper.git
cd git-diff-helper
# Install development dependencies
pip install -r requirements-dev.txt
# Install in editable mode
pip install -e .
# Run tests
pytest
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the need for better AI code review workflows
- Built with Python's excellent subprocess and pathlib libraries