Skip to content

qzhao19/auto-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

auto-commit

Git Commit Message Auto-Generation Tool Using Python

Table of Contents

  1. Introduction
  2. Features
  3. Installation
  4. Usage
  5. Configuration
  6. License

Introduction

The auto-commit is a Python-based utility designed to automatically generate meaningful Git commit messages. It analyzes changes in your Git repository and produces descriptive commit messages, saving you time and ensuring consistent commit message formatting.

Features

  • Automatic Analysis: Scans staged changes (after git add or git rm) to generate relevant commit messages, aligning with standard Git workflows.
  • Git Integration: Seamlessly integrates with Git workflow through git auto-commit alias after installation.
  • Interactive CLI: Generates commit messages through an interactive command-line interface.
  • Multiple Templates: Supports different commit message templates to suit various workflows.
  • Customizable Rules: Allows users to define custom rules for commit message generation.

Installation

System Requirements: Currently only supports on Linux system. Contributions for Windows or macOS compatibility are welcome from interested developers.

Automated Installation

We provide an installation script (install.sh) that handles:

  1. Creating a Python virtual environment (venv) and installing dependencies
  2. Deploying the auto-commit.sh script to your home directory (~/.auto-commit.sh)
  3. Setting up the Git alias git auto-commit

Run the installer with:

chmod +x install.sh && ./install.sh

Manual Installation (Advanced)

For custom setups, you can:

  1. Modify the script template from scripts/auto-commit.sh
cp scripts/auto-commit.sh ~/.auto-commit.sh
vi ~/.auto-commit.sh  # Make your custom edits
  1. Set execute permissions:
chmod +x ~/.auto-commit.sh
  1. Create Git alias manually:
git config --global alias.auto-commit '!f() { ~/.auto-commit.sh; }; f'

Usage

To use the auto-commit tool, run the following command:

git auto-commit

This will open an interactive CLI where you can select the commit message template and provide any additional information.

Description of the image

Example workflow showing:

  1. Running git auto-commit after staging changes
  2. Reviewing the generated commit message on interactive mode
  3. Using Tab to accept or Enter to regenerate

Configuration

Environment Variables

The file .env in your project root configures AI parameters:

# Local AI Settings
LLM_MODEL = "qwen2.5:0.5b"       # Model name/version
LLM_HOST = "http://localhost:11434"  # Local AI server URL

# OpenAI Settings (alternative)
OPENAI_API_KEY = "your-api-key-here"           # Required for OpenAI API
OPENAI_API_BASE = "https://api.openai.com/v1"  # OpenAI endpoint

# Generation Parameters
SYSTEM_PROMPT = ""               # Custom instruction template
TIMEOUT = 60                     # API timeout in seconds
MAX_TOKENS = 2000                # Max response length
TEMPERATURE = 0.8                # Creativity vs determinism (0-1)

The system automatically detects which to use based on:

  • If LLM_MODEL starts with gpt AND OPENAI_API_KEY exists → Uses OpenAI
  • Otherwise → Uses local LLM with specified LLM_HOST

You can switch between them just by changing the .env file - no code changes needed!

Local LLM Setup

Here's how to setup local LLM model via Ollama:

# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
# pull your desired model 
ollama pull llama2
# run your local LLM server
ollama serve

Prompt Customization

Modify src/template/system_prompt.j2 to change AI behavior:

{# Example customization - Add new commit type rule #}
You are an expert software engineer analyzing Git changes...

License

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

About

Git Commit Message Auto-Generation Tool Using Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published