Skip to main content

LLM plugin to generate git commit messages and interactively commit.

Project description

llm-git-commit

LLM plugin to generate Git commit messages based on repository changes and interactively commit.

Installation

This plugin requires LLM to be installed.

For local development / current usage:

  1. If you have the code in a directory (e.g., you cloned it or created it locally):

    cd path/to/your/llm-git-commit 
    
  2. Install in editable mode within your LLM environment:

    llm install -e .
    

    (This command installs the plugin so llm can find it, and the -e flag means changes to the code are reflected immediately without reinstalling.)

(Future: Once published, installation will be simpler, e.g., llm install llm-git-commit)

Usage

From within a Git repository, run:

llm git-commit

This command will:

  1. Identify changes in your Git repository (staged changes by default).
  2. Send these changes to your configured Large Language Model.
  3. Present the LLM-generated commit message for you to review and edit.

Interactive Editing:

  • You can edit the suggested message.
  • Press Enter to add a new line within the message.
  • To submit the message and proceed to commit, press Esc then Enter.
  • To cancel, press Ctrl+C or Ctrl+D.

After submitting the message (or if using -y), you'll get a final confirmation before git commit is executed.

Options

  • --staged: (Default) Uses staged changes (git diff --staged).
  • --tracked: Uses all changes to tracked files (git diff HEAD). Commits with git commit -a.
  • -m MODEL_ID, --model MODEL_ID: Specify which LLM model to use.
  • -s SYSTEM_PROMPT, --system SYSTEM_PROMPT: Use a custom system prompt.
  • -y, --yes: Skip interactive editing and use the LLM's suggestion directly (still asks for final commit confirmation).

The System Prompt

The plugin uses a specific system prompt to guide the LLM in generating commit messages. Here's the default:

You are an expert programmer tasked with writing a concise and conventional git commit message.
Analyze the provided 'git diff' output, which details specific code changes.
Your goal is to create a commit message that SUCCINCTLY summarizes THESE CODE CHANGES.

**Format Rules:**
1.  **Conventional Commits:** Start with a type, followed by an optional scope, a colon, and a space. Then, a short, imperative-mood description of the change.
    - Types: `feat` (new feature), `fix` (bug fix), `docs` (documentation), `style` (formatting), `refactor` (code structure), `test` (adding/improving tests), `chore` (build/tooling changes).
    - Example: `feat: add user authentication module`
    - Example: `fix(api): correct pagination error in user endpoint`
    - Example: `chore: configure linting tools`
2.  **Subject Line:** The first line (subject) MUST be 50 characters or less. It should summarize the most important aspect of the changes.
3.  **Body (Optional):**
    - If more detail is needed to explain the *what* and *why* of the code changes, add a SINGLE BLANK LINE after the subject.
    - The body should consist of one or more paragraphs. Keep these concise and focused on the changes.
    - Bullet points (using `-` or `*`) are acceptable in the body for listing multiple related changes.

**Content Guidelines - CRITICAL:**
- **Focus ONLY on the code modifications presented in the diff.**
- If the diff adds new files (e.g., a new script, module, or entire plugin), describe the *primary purpose or core functionality these new files introduce* as a collective change.
- **DO NOT:**
    - Write a project description, a general list of features of the software, or a tutorial.
    - Describe the *mere existence* of files (e.g., AVOID "Added llm_git_commit.py and pyproject.toml").
    - Be overly verbose or conversational.
    - List all functions or methods added unless they are critical to understanding the change at a high level.

**Example Scenario: Adding a new plugin (like the one you might be committing now):**
If the `git diff` output shows the initial files for a new "git-commit" plugin, a good commit message would look like this:

feat: implement initial llm-git-commit plugin

Provides core functionality for generating Git commit messages
using an LLM based on repository changes.

- Includes command structure for `llm git-commit`.
- Implements logic for retrieving git diffs (staged/tracked).
- Integrates LLM prompting for message generation.
- Adds interactive editing of suggested messages.

**Output Requirements:**
Return ONLY the raw commit message text. Do not include any explanations, markdown formatting (like '```'), or any phrases like "Here's the commit message:".

Development

To set up this plugin locally for further development:

  1. Ensure you have the project code in a local directory.
  2. It's recommended to use a Python virtual environment:
    cd path/to/your/llm-git-commit
    python3 -m venv venv
    source venv/bin/activate  # On Linux/macOS
    # .\venv\Scripts\activate  # On Windows
    
  3. Install the plugin in editable mode along with its dependencies (including llm itself if not in the venv):
    pip install -e .
    
    Now you can modify the code, and the changes will be live when you run llm git-commit.

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

llm_git_commit-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

llm_git_commit-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file llm_git_commit-0.1.0.tar.gz.

File metadata

  • Download URL: llm_git_commit-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for llm_git_commit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b42795215d50a20606b1dcb9fe44ab196b5255f933a280eae0219557f452dd0d
MD5 c0a4d40585fb838c86a80f684bb07a5d
BLAKE2b-256 75ae13b24daf5bb06ffc484c01183c58c488366f84c73e46d41e9e0ac2d70789

See more details on using hashes here.

File details

Details for the file llm_git_commit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llm_git_commit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for llm_git_commit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a9dc0c521b0687b963b3a11ff6203e665087b2b9b90cd54a1b2a7bf2c8006ac
MD5 b0289dab92c62b031bcf4448dbad0a53
BLAKE2b-256 b1ce44cc0ad453bdf52b27d3448f6fc800323185139f0c079ea1e349d8e9be2c

See more details on using hashes here.

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