Skip to content

AI-Powered Commit Message Generator (Flan-T5) #303

@DarshanCode2005

Description

@DarshanCode2005

📋 Overview

Writing meaningful Git commit messages is often skipped or done poorly. This project automates commit message generation by summarizing code changes with a small, offline LLM the Flan-T5 model ensuring it works on any machine without a GPU.


🎯 Objectives

  • Automatically generate descriptive commit messages from Git diffs.
  • Maintain a lightweight, offline workflow suitable for developers with CPU-only machines.
  • Provide an easy-to-use CLI or pre-commit hook integration.

⚙️ Features

  1. Diff Analysis: Extracts staged Git changes.
  2. AI Commit Generation: Uses Flan-T5 to generate human-readable messages.
  3. Commit Type Support: Optionally categorize messages as feat, fix, docs, etc.
  4. CLI Interface: Quick command-line usage:
python commitgen.py --type feat
  1. Offline & CPU-Friendly: No GPU required; runs on small laptops or cloud servers.

🧩 Tech Stack

  • Python 3.12+
  • Libraries: transformers, torch, argparse, subprocess

📂 Project Structure

ai-commit-gen/
├── commitgen.py          # CLI tool
├── utils.py              # Git diff extraction and helpers
├── requirements.txt
├── README.md
└── examples/
    └── sample_diff.txt

🧪 Example Workflow

# Stage changes
git add .

# Generate AI commit message
python commitgen.py --type feat

# Output:
# ✨ Suggested Commit:
# "feat(auth): refactored login validation and added password length checks"

🚀 Advantages

  • Fully offline, CPU-compatible, no API keys required.
  • Lightweight (Flan-T5 small model ~240 MB).
  • Improves commit quality and project maintainability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions