🧠🤖 This tool generates AI-powered commit messages via Git hooks, automating meaningful message suggestions from OpenAI and others to improve commit quality and efficiency.
Generates a commit message based on the git diff
result using the OpenAI API.
This repository is available at NuGet under the name AICommitMessage.
- Install the tool globally (or per project/repository).
- Move to the project folder.
- Install the Git hook on the default
hooks
directory.
dotnet tool install -g AiCommitMessage
cd my-project/
dotnet-aicommitmessage install-hook
git add .
git commit -m ""
Use git log -1
to review the last commit details and find the automatically generated commit message.
To configure and use models with dotnet-aicommitmessage
, users need to set their settings once. This setup involves specifying the model, API key, and API URL. These settings will be stored as environment variables for future use.
Run the following commands to configure the model and related settings:
dotnet-aicommitmessage set-settings -m gpt-4o-mini -k {api-key} -u {api-url}
dotnet-aicommitmessage set-settings -m llama-3-1-405b-instruct -k {api-key} -u {api-url}
Replace {api-key}
with your API key and {api-url}
with the URL of your API provider.
After the initial setup, you can easily switch between models without needing to provide the API key or URL again:
dotnet-aicommitmessage set-settings -m gpt-4o-mini
dotnet-aicommitmessage set-settings -m llama-3-1-405b-instruct
This allows for quick model changes while retaining your previously configured API details.
Currently supported models are gpt-4o-mini
and llama-3-1-405b-instruct
.
The training model for the AI used is designed using as reference these guidelines:
- Conventional Commits v1.0.0.
- Padrões de Commits (in Portuguese).
- Conventional Commit Messages.
- Emoji for Conventional Commits.
- conventional-commit-types.
Here’s a flow diagram showing the sequence of execution of the prepare-commit-msg
hook and its integration with dotnet-aicommitmessage
to generate commit messages using the OpenAI API:
graph TD
A[Git Commit] --> B[prepare-commit-msg Hook Trigger]
B --> C[Invoke dotnet-aicommitmessage Tool]
C --> D[Send Data to OpenAI API]
D --> E[Generate Commit Message]
E --> F[Check and append pre-defined commands to Commit Message]
F --> G[Return Generated Commit Message]
G --> H[Insert Commit Message into Git Commit]
H --> I[Finalize Commit]
This tool accepts an argument as the command to execute. Here is a list of available commands:
Command | Description |
---|---|
install-hook |
Installs GIT hooks in the default .git/hooks directory or in the custom directory configured in GIT settings. |
generate-message |
Generates a commit message based on the current changes (git diff context). |
set-settings |
Set the OpenAI settings. |
help |
Display information about this program. |
version |
Display version information. |
Here is an example of the commit messages generated in a real-world project:
You can run the message generation manually to debug it, but it will not commit the content to your GIT repository.
If you also want to check the OpenAI JSON response, append the -D
parameter.
To manually generate a commit message without committing the staged changes, run the following command:
dotnet-aicommitmessage generate-message -m "."
If you want to persist the OpenAI JSON response, add the -D
parameter, and a debug.json
file will be created with the response JSON.
dotnet-aicommitmessage generate-message -Dm "."
Here is a sample debug.json
content:
{
"Value": {
"CreatedAt": "2024-11-20T12:54:03+00:00",
"FinishReason": 0,
"ContentTokenLogProbabilities": [],
"RefusalTokenLogProbabilities": [],
"Role": 2,
"Content": [
{
"Kind": 0,
"Text": "feat - add reactivation handling for refunds due today",
"ImageUri": null,
"ImageBytes": null,
"ImageBytesMediaType": null,
"ImageDetailLevel": null,
"Refusal": null
}
],
"ToolCalls": [],
"Refusal": null,
"FunctionCall": null,
"Id": "chatcmpl-[[REDACTED]]",
"Model": "gpt-4o-mini-2024-07-18",
"SystemFingerprint": "fp-[[REDACTED]]",
"Usage": {
"OutputTokenCount": 10,
"InputTokenCount": 6229,
"TotalTokenCount": 6239,
"OutputTokenDetails": {
"ReasoningTokenCount": 0
}
}
}
}
Guilherme Branco Stracini |
Malay Kumar |
Ryan Flores |
dependabot[bot] |
penify-dev[bot] |
gitauto-ai[bot] |
Snyk bot |
CodeFactor |