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
- Set your API key:
export D2C_API_KEY='your-openai-api-key'
- Stage your changes:
git add .
- 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 featurefix: A bug fixdocs: Documentation changesstyle: Formatting changesrefactor: Code refactoringperf: Performance improvementstest: Adding or modifying testsbuild: Build system changesci: CI configuration changeschore: 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with Typer for CLI
- Rich for beautiful terminal output
- GitPython for Git operations
- Inspired by the Conventional Commits specification
Support
Made with ❤️ by maadhav-codes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07e64e9eeeb36c34b46c453ef8d0897410e423a2923be93a550ee4d747e577e3
|
|
| MD5 |
613a7fb371d6ec447bd86059ed55d844
|
|
| BLAKE2b-256 |
158c0a2a01dcbd23f3c69362e46c422b095b8707792507083a291e65d346e6c0
|
Provenance
The following attestation bundles were made for diff2commit-1.0.1.tar.gz:
Publisher:
ci.yml on maadhav-codes/diff2commit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
diff2commit-1.0.1.tar.gz -
Subject digest:
07e64e9eeeb36c34b46c453ef8d0897410e423a2923be93a550ee4d747e577e3 - Sigstore transparency entry: 659671355
- Sigstore integration time:
-
Permalink:
maadhav-codes/diff2commit@55b2ff3e8f39d9ff0f51933668f0fa52406ece3d -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/maadhav-codes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@55b2ff3e8f39d9ff0f51933668f0fa52406ece3d -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffb6580503ccc2037476aedb0535a5beb188db4c07b5a58f5a2e7ac3452770bf
|
|
| MD5 |
17c5bd8eae72a00fc6b116446d87b603
|
|
| BLAKE2b-256 |
704d1769d7581389743d652217a1cdacf649ff30965e53058ef245ec1115cf33
|
Provenance
The following attestation bundles were made for diff2commit-1.0.1-py3-none-any.whl:
Publisher:
ci.yml on maadhav-codes/diff2commit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
diff2commit-1.0.1-py3-none-any.whl -
Subject digest:
ffb6580503ccc2037476aedb0535a5beb188db4c07b5a58f5a2e7ac3452770bf - Sigstore transparency entry: 659671367
- Sigstore integration time:
-
Permalink:
maadhav-codes/diff2commit@55b2ff3e8f39d9ff0f51933668f0fa52406ece3d -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/maadhav-codes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@55b2ff3e8f39d9ff0f51933668f0fa52406ece3d -
Trigger Event:
release
-
Statement type: