🧠🧰 This tool generates AI-powered commit messages via Git hooks, automating meaningful message suggestions from OpenAI and others to improve commit quality and efficiency.
Caution
This is still in development/beta. It will be GA when a major release 1.0 becomes available.
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.
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: