I Built An AI Git Commit Message Generator
I used to write bad commit messages.
Messages like "fixed bug" or "updated stuff" were common. This made my pull requests messy. I decided to build an AI tool to automate this. I wanted to generate clear, professional messages from my code diffs.
It was harder than I thought. You cannot just use a simple prompt.
Here is what I learned from the process:
The Failures
- Initial attempts were too wordy. The AI wrote paragraphs instead of short lines.
- The AI ignored standard formats like Conventional Commits.
- Adding more instructions caused the AI to hallucinate changes that were not there.
- Local models were too slow or wrote in a strange, poetic style.
The Solution
I built a hybrid system in Node.js using three steps:
- Type Classification: I force the AI to pick a type first (feat, fix, chore, etc.).
- Context Truncation: I only send the first 250 lines of the diff. This saves money and stays focused.
- Validation: I use a regex to check the output. If it fails, the script tries again.
My Technical Settings
- Model: I use GPT-4o-mini. It is fast and cheap.
- Temperature: I set it to 0.2. Low temperature ensures boring, consistent messages.
- Workflow: I do not auto-commit. I use the tool to suggest a message, then I review and paste it manually.
Lessons for Developers
- Token limits are your main enemy. Large diffs will break your budget or the prompt.
- Validation is required. Without a regex check, you will get useless text.
- Manual review is safety. AI makes mistakes. Never let it commit without your eyes on it.
- Privacy matters. Do not send sensitive code to an external API if your company forbids it.
If you want to try this, run it as a Git alias. It makes the process seamless.
Optional learning community: https://t.me/GyaanSetuAi
