- Fixed indentation error in ollama_client.py (extra space before docstring) - Created missing message_generator.py module - Fixed ChangelogGenerator to accept git_utils parameter - Updated message_generator change type detection to prioritize test indicator - Fixed test fixtures to properly pass mocked dependencies
Git Commit Message Generator CLI
A CLI tool that generates git commit messages and conventional changelogs from staged/unstaged diffs using local LLMs (Ollama, llama.cpp). Features privacy-first operation with no external API calls, supports conventional commits format, includes interactive mode for message refinement, auto-detects change types, and can generate CHANGELOG.md from git history.
Features
- Privacy-First: All processing happens locally using Ollama - no external API calls
- Conventional Commits: Generates messages following the conventional commits format
- Interactive Mode: Refine and edit messages before committing
- Auto-Detection: Automatically detects change types (feat, fix, docs, etc.)
- Scope Detection: Identifies affected areas from file paths
- Changelog Generation: Creates CHANGELOG.md from git history
- Flexible Configuration: Supports environment variables and config files
Installation
pip install git-commit-message-generator
Or from source:
pip install -e .
Prerequisites
- Python 3.9+
- Ollama running locally
- A supported model (llama3, codellama, etc.)
Install Ollama and pull a model:
# Install Ollama from https://ollama.ai
ollama serve
ollama pull llama3
Usage
Generate Commit Message
Generate a commit message from staged changes:
git-commit-gen generate
Generate from unstaged changes:
git-commit-gen generate --unstaged
Use interactive mode for message refinement:
git-commit-gen generate --interactive
Specify a different model:
git-commit-gen generate --model codellama
Write message to file:
git-commit-gen generate -o commit-message.txt
Generate Changelog
Generate a changelog from git history:
git-commit-gen changelog
Generate with a limit on commits:
git-commit-gen changelog --limit 100
Generate simple changelog (without LLM):
git-commit-gen changelog --simple
Write to file:
git-commit-gen changelog -o CHANGELOG.md
Check Status
Check system status and configuration:
git-commit-gen status
Configure Settings
Show current configuration:
git-commit-gen config --show
Set default model:
git-commit-gen config --model llama3
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
OLLAMA_HOST |
Ollama server URL | http://localhost:11434 |
OLLAMA_MODEL |
Default model to use | llama3 |
GIT_COMMIT_GENERATOR_CONFIG |
Path to config file | - |
Config File
Create a config.yaml file:
ollama_host: http://localhost:11434
ollama_model: llama3
Prompt Templates
Customize generation prompts by creating files in the prompts directory:
prompts/commit_message.txt- Template for commit message generationprompts/changelog.txt- Template for changelog generation
Error Handling
| Error | Solution |
|---|---|
| Ollama connection failed | Check if Ollama is running, verify host URL |
| No staged changes | Stage with git add or use --unstaged |
| Invalid format | Regenerate or manually edit |
| Git repo not found | Run from within a git repository |
| Model not found | Pull with ollama pull <model_name> |
Development
Running Tests
pytest tests/ -v --cov=src --cov-report=term-missing
Project Structure
git-commit-message-generator/
├── src/git_commit_generator/
│ ├── __init__.py
│ ├── __main__.py # Entry point
│ ├── cli.py # CLI interface
│ ├── config.py # Configuration management
│ ├── git_utils.py # Git operations
│ ├── ollama_client.py # Ollama integration
│ ├── message_generator.py # Commit message generation
│ ├── changelog_generator.py # Changelog generation
│ └── interactive.py # Interactive mode
├── prompts/
│ ├── commit_message.txt
│ └── changelog.txt
├── tests/
│ ├── test_cli.py
│ ├── test_git_utils.py
│ ├── test_message_generator.py
│ ├── test_changelog_generator.py
│ └── conftest.py
├── pyproject.toml
├── requirements.txt
└── README.md
License
MIT