This Node.js script automatically generates concise and descriptive Git commit messages using OpenAI's API. It analyzes your staged changes and provides a meaningful commit message in two parts:
- Summary: A brief overview (no more than 50 characters).
- Description: Bullet points outlining the changes.
- Extracts staged Git changes
- Functional programming style using Ramda for cleaner code
- Utilizes OpenAI GPT-4 for generating commit messages
- Support to use local model(deepseek-r1 on ollama) with USE_LOCAL_MODEL=true.
- Check if the diff is an atomic PR and offer a reason.
- Security
- Sanitize diffs and filenames.
- Restrict to safe file types
- Remove comments.
- Confirmation diff before send.
- Enable to use local model with ollama, avoid code exposure.
- Anonymize variable names [On the way]
-
Install it globally.
npm install -g commit-summarize
-
Install the required packages:
export USE_LOCAL_MODEL=true && commit-summarize or export OPEN_API_KEY_COMMIT=YOUR_KEY && commit-summarize
Or clone the repository and run it locally.
- Clone the repository:
git clone https://github.com/chienweiluo/commit-summarize.git cd commit-summarize
- Install the required packages.
- Copy the index.cjs to your project and run it.
node index.cjs
- Run the script:
- If you want to use OpenAI API, you can set the following environment variable:
export OPEN_API_KEY_COMMIT=YOUR_KEY && node index.cjs
- If you want to use local model (deepseek-r1 on ollama), you can set the following environment variable:
export USE_LOCAL_MODEL=true && node index.cjs
After running the script, it will ask you to confirm the diff.
-
Check the diff and answer the yes/no question to confirm the diff.
-
Wait for the script to generate the commit message. like this:
**Summary:** Update environment variable handling and logging
**Description:**
- Changed the environment variable from `XXX` to `YYY`.
- Updated console log message for empty changed files for improved clarity.
...
The main idea of this script is inspired by an article from August. Many thanks to him for his outstanding articles.
Related Links
AI Git Commit by August@letswritetw
How To Get Your Own OpenAI API Key
This project is licensed under the MIT License.
This document is generated by AI.