Skip to main content

CLI tool that automatically generates clear, descriptive commit messages from staged Git diffs using AI

Project description

diff2commit

🤖 An AI-powered Git commit message generator that creates clear, descriptive commit messages following the Conventional Commits specification.

Features

  • AI-Powered Generation: Leverages GPT-4, Claude, or Gemini to analyze your changes and generate meaningful commit messages.
  • Conventional Commits: Automatically formats messages according to the Conventional Commits specification.
  • Interactive Review: Review, edit, and approve messages before committing.
  • Multiple AI Providers: Support for OpenAI, Anthropic Claude, and Google Gemini.
  • Cost Tracking: Monitor token usage and API costs.
  • Customizable: Configure models, prompts, and message formats.
  • Beautiful CLI: Rich terminal UI with syntax highlighting.

Installation

From PyPI (Recommended)

pip install diff2commit

From Source

git clone https://github.com/maadhav-codes/diff2commit.git
cd diff2commit
pip install -e .

Using pipx (Isolated Installation)

pipx install diff2commit

Quick Start

  1. Set your API key:
export D2C_API_KEY='your-openai-api-key'
  1. Stage your changes:
git add .
  1. Generate and commit:
diff2commit generate

Usage

Generate Commit Message

# Generate with interactive review
diff2commit generate

# Generate multiple suggestions
diff2commit generate --count 3

# Use a different AI provider
diff2commit generate --provider anthropic

# Use specific model
diff2commit generate --model gpt-4-turbo

# Skip interactive review
diff2commit generate --no-review

# Generate without committing
diff2commit generate --no-commit

View Usage Statistics

# Total usage
diff2commit usage

# Current month usage
diff2commit usage --monthly

# Usage by provider
diff2commit usage --by-provider

View Configuration

diff2commit config

Version Information

diff2commit version

Configuration

Environment Variables

Create a .env file in your project or set environment variables:

# Required
D2C_API_KEY=your-api-key-here

# Optional
D2C_AI_PROVIDER=openai          # openai, anthropic, or gemini
D2C_AI_MODEL=gpt-4              # Model name
D2C_MAX_TOKENS=200           # Max tokens for generation
D2C_TEMPERATURE=0.7          # Sampling temperature (0.0-2.0)
D2C_COMMIT_FORMAT=conventional
D2C_INCLUDE_EMOJI=false
D2C_MAX_SUBJECT_LENGTH=72
D2C_TRACK_USAGE=true

Configuration File

Create ~/.config/diff2commit/config.toml:

ai_provider = "openai"
ai_model = "gpt-4"
max_tokens = 200
temperature = 0.7
commit_format = "conventional"
include_emoji = false
max_subject_length = 72
track_usage = true

Conventional Commits Format

The tool generates messages following the Conventional Commits specification:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Types

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation changes
  • style: Formatting changes
  • refactor: Code refactoring
  • perf: Performance improvements
  • test: Adding or modifying tests
  • build: Build system changes
  • ci: CI configuration changes
  • chore: Other changes

AI Providers

OpenAI (GPT-4)

export D2C_API_KEY='sk-...'
export D2C_AI_PROVIDER='openai'
export D2C_AI_MODEL='gpt-4'

Anthropic Claude

export D2C_API_KEY='sk-ant-...'
export D2C_AI_PROVIDER='anthropic'
export D2C_AI_MODEL='claude-3-sonnet-20240229'

Google Gemini

export D2C_API_KEY='AI...'
export D2C_AI_PROVIDER='gemini'
export D2C_AI_MODEL='gemini-pro'

Cost Management

Track and manage API costs:

# View total costs
diff2commit usage

# View monthly costs
diff2commit usage --monthly

# Set monthly limit (in config)
D2C_COST_LIMIT_MONTHLY=10.0

Development

Setup Development Environment

git clone https://github.com/maadhav-codes/diff2commit.git
cd diff2commit
pip install -e ".[dev]"

Run Tests

pytest tests/

Linting

ruff check .
black --check .
mypy src/

Format Code

black .
ruff check --fix .

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

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

Acknowledgments

Support


Made with ❤️ by maadhav-codes

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

diff2commit-1.0.1.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

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

diff2commit-1.0.1-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file diff2commit-1.0.1.tar.gz.

File metadata

  • Download URL: diff2commit-1.0.1.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for diff2commit-1.0.1.tar.gz
Algorithm Hash digest
SHA256 07e64e9eeeb36c34b46c453ef8d0897410e423a2923be93a550ee4d747e577e3
MD5 613a7fb371d6ec447bd86059ed55d844
BLAKE2b-256 158c0a2a01dcbd23f3c69362e46c422b095b8707792507083a291e65d346e6c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for diff2commit-1.0.1.tar.gz:

Publisher: ci.yml on maadhav-codes/diff2commit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file diff2commit-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: diff2commit-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for diff2commit-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ffb6580503ccc2037476aedb0535a5beb188db4c07b5a58f5a2e7ac3452770bf
MD5 17c5bd8eae72a00fc6b116446d87b603
BLAKE2b-256 704d1769d7581389743d652217a1cdacf649ff30965e53058ef245ec1115cf33

See more details on using hashes here.

Provenance

The following attestation bundles were made for diff2commit-1.0.1-py3-none-any.whl:

Publisher: ci.yml on maadhav-codes/diff2commit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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