Skip to main content

A tool for generating Git diff reports optimized for AI code review

Project description

Git Diff Helper

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.

Quick Start

# 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

Features

  • 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

Installation Options

From PyPI (Recommended)

pip install git-diff-helper

From GitHub

pip install git+https://github.com/mlusas/git-diff-helper.git

For Development

git clone https://github.com/mlusas/git-diff-helper.git
cd git-diff-helper
pip install -e .

Usage

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

Command Line Options

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

Output Files

The tool generates three Markdown files:

  1. diff_file_diffs.md: Contains the actual diffs showing what changed
  2. diff_file_originals.md: Contains the original content of changed files
  3. diff_file_updated.md: Contains the current content of changed files

AI Code Review Workflows

Using with ChatGPT/Claude

  1. 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
  1. Share the generated files with the AI:

    • diff_file_diffs.md for a quick overview of changes
    • diff_file_originals.md and diff_file_updated.md for deeper context
    • Use the AI's context window efficiently by sharing only relevant parts
  2. 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"

Using with GitHub Copilot

  1. 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"
  1. Open the diff files alongside your code
  2. Use Copilot suggestions while reviewing the changes

Advanced Usage

As a Python Module

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}")

Integration Examples

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

Contributing

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.

Development Setup

# 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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Inspired by the need for better AI code review workflows
  • Built with Python's excellent subprocess and pathlib libraries

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_diff_helper-0.1.7.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_diff_helper-0.1.7-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file git_diff_helper-0.1.7.tar.gz.

File metadata

  • Download URL: git_diff_helper-0.1.7.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.9

File hashes

Hashes for git_diff_helper-0.1.7.tar.gz
Algorithm Hash digest
SHA256 39079598c2475827e42976c3e16ecb8a03eb97a5e25756f6f09d589198dd0a5a
MD5 e5f9d138f2222b32ab412d5604b540b7
BLAKE2b-256 c56c7fbeefcc8633a6ec5e70bc02ac1e254567fcb9c94c65b40358836e1d1e9b

See more details on using hashes here.

File details

Details for the file git_diff_helper-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for git_diff_helper-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 128e6b319539c78ae0c4ec54b024cecc1fb4ff40c0e757702564cc198657d19c
MD5 4159f8519260ccff76be33edad3b8798
BLAKE2b-256 936dc725f0099840e05ae792bfc12b20f2d587aec9b5d1bd219079c22f2e0ac2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page