This program is a commit message generator that leverages GPT-4 or GPT-3.5-turbo to create detailed and informative commit messages for your source control.
- Python 3
- openai
- tiktoken
- An OpenAI API key
- Install the program:
pip3 install gpt-commit-msg
- Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY="your_openai_api_key"
The program can be run in two ways:
- Piping a diff into the script:
diff -u old_file new_file | gpt-commit-msg
- Using the --git flag to automatically use staged git changes:
gpt-commit-msg --git
By default, the script uses GPT-3.5-turbo, which is faster and costs less. To use GPT-4 instead, add the -4 flag:
gpt-commit-msg -4
The script reads a diff from either stdin or staged git changes, and then creates a commit message using OpenAI's GPT. It handles large diffs by splitting and summarizing the input until it fits within the model's token limit.
The generated commit message will start with a one-line summary of 60 characters, followed by a blank line, and then a longer but concise description of the changes.
I use the following two macros in my .vimrc to easily invoke this command when writing a commit message.
command! CommitMsg :r !gpt-commit-msg --git
command! CommitMsg4 :r !gpt-commit-msg --git -4
Every change description in this project's history also came courtesy of this script.