Generates a commit message from a git diff using AI.
Features
- Supports OpenAI-like providers, with Gemini as the default.
- Improve commit messages by switching to a model based on diff size.
Note
The commit messages for this project were generated using this tool.
Download the precompiled binary from the releases page that matches your current
system. Unzip the file and place the binary in a location available on your
PATH environment variable.
Instructions for non-Nix users
Add a .pre-commit-config.yaml file to your project's root directory with the
following content:
- repo: local
hooks:
- id: auto-commit-msg
name: auto-commit-msg
entry: acm
language: system
stages: [prepare-commit-msg]Instructions for Nix users
Add the auto-commit-msg input to the devenv.yaml file:
inputs:
auto-commit-msg:
url: github:sestrella/auto-commit-msg
overlays: [default]
nixpkgs:
url: github:cachix/devenv-nixpkgs/rollingAdd the auto-commit-msg hook to the devenv.nix file as follows:
{ pkgs, lib, ... }:
{
dotenv.enable = true;
git-hooks.hooks.auto-commit-msg = {
enable = true;
entry = lib.getExe pkgs.auto-commit-msg;
stages = [ "prepare-commit-msg" ];
};
cachix.pull = [ "sestrella" ];
}Note: Enabling dotenv is optional if the OPENAI_API_KEY environment
variable is available.
auto-commit-msg can be configured via a .auto-commit-msg.toml file in
the project's root directory or the user's home directory. The available
configuration parameters are:
-
trace: Whentrue, appends auto-commit-msg execution traces to the commit message.- Default:
false
The following metrics are appended to the commit message when trace is enabled:
Version: The version of theauto-commit-msgcommand used.Model: The model used to generate the commit message.ResponseTime: The time it took to get a response from the AI model.ExecutionTime: The total time it took for theauto-commit-msgcommand to execute.
- Default:
-
provider.base_url: The base URL of the OpenAI-like provider.- Default:
https://generativelanguage.googleapis.com/v1beta/openai
- Default:
-
provider.api_key: The name of the environment variable that contains the API key.- Default:
GEMINI_API_KEY
- Default:
-
diff.short_model: The model to use for diffs with fewer lines thandiff.threshold.- Default:
gemini-2.5-flash-lite
- Default:
-
diff.long_model: The model to use for diffs with more lines thandiff.threshold.- Default:
gemini-2.5-flash
- Default:
-
diff.threshold: The line count threshold to switch betweendiff.short_modelanddiff.long_model.- Default:
500
- Default:
Here is an example .auto-commit-msg.toml file:
trace = true
[provider]
base_url = "https://api.openai.com/v1"
api_key = "OPENAI_API_KEY"
[diff]
short_model = "gpt-4.1-mini"
long_model = "o4-mini"
threshold = 250After setting auto-commit-msg as a prepare-commit-msg hook, invoking git commit without a commit message generates a commit message. If a commit message
is given, auto-commit-msg does not generate a commit message and instead uses
the one provided by the user.
The following table compares the Go and Rust implementations; it was built using hyperfine.
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
./auto-commit-msg |
1.101 ± 0.205 | 0.776 | 1.309 | 1.00 |
./rust/target/release/acm |
1.244 ± 0.106 | 1.127 | 1.416 | 1.13 ± 0.23 |
