GPT-3 has proven to be a valuable tool for assisting in technical tasks such as scripting and command line operations. With gptcommit, you no longer have to spend time writing your commit messages. Install
gptcommit and let GPT-3 do the writing for you.
Commit messages are a key channel for developers to communicate their work with others, especially in code reviews. When making complex code changes, it can be tedious to thoroughly document the contents of each change. I often felt the impulse to just title my commit “fix bug” and move on. These one-liner messages often lack the full context that a review would need to understand the change. Worse, a seemingly harmless commit description like “fix typo” might omit key changes made elsewhere in the codebase. Surfacing these changes with gptcommit helps the author and reviewer by bringing attention to these additional changes.
Get setup in minutes
Prerequisites: To use
gptcommit, you’ll need to have
1) Install the
gptcommit binary from cargo
cargo install --locked gptcommit
2) In a local git repository, run the following to set up the
gptcommit githooks. Note that this command needs to be run for each local git checkout that you have.
2) In your dotfiles or your working shell, set the
OPENAI_API_KEY to your key.
Consider adding the line above to your ~/.bashrc, ~/.zshrc or equivalent dotfile.
Demos and Results on real commits
See the ASCII screencasts below:
- Demo #1: the full installation and commit workflow, editing multiple rust files
- Demo #2: a one-line change to a string inside a rust file.
- Demo #3: Modifying non-code files, in this case a README.
If you’ve found compelling commit summaries with
gptcommit, I’d appreciate hearing from you.
Building on Prior Work
gptcommit this tool was inspired took heavy inspiration from previous commit summarizing tools including:
This tool is currently not working, as it used an unofficial API to prompt ChatGPT. gptcommit uses the official completions API from OpenAI and requires users to bring their OpenAI API key. gptcommit integrates as a githook so it can run seamlessly as part of the git workflow. Finally, gptcommit uses Rust so which allows for quicker execution times.
This tool integrates via GitHub actions rather than in the git workflow Summarization occurs at the PR level rather than per commit. The action is already triggered after a pull request has already been summarized, and posted directly to the pull requests without human review. Many aspects of the prompt design were borrowed from this project.
gptcommit focuses on the
git commit workflow such that the commit author could approve or edit any output from GPT.
Behind the scenes
Ingestion of a git commit occurs in two phases.
First, each file is summarized independently and in parallel to produce a list of bullet points from OpenAI’s models.
Then, the summarized file changes are summarized in two ways. First, the model is instructed to generate a short, one-line title for the commit. In addition, the model summarized higher-level bullet points to be included in the body of the commit message.
The final output provided to the commit message then consists of:
[title] - [summary point 1] - [summary point 2...] [/changed/file A] - [file summary point 1] - [file summary point 2...] [/changed/file B...] - [file summary point 1...] ...
Try it yourself
cargo install --locked gptcommit or check out the repo for more details. You’ll need an OpenAI API key (the default model is GPT-3) and you’ll have to install the githook in each repo you work in.
Some interesting follow ups I’m thinking about include:
How can we create a smoother commit workflow that allows interactive editing with GPT-like language models?
How should we better structure the prompts to summarize bigger commits that we skip for now?
How should we collect user feedback to better train the summarizer models?
Lastly, if you encounter any bugs or have any suggestions for improvements, please open an issue on the repository
Thanks to Itay Knaán-Harpaz and his work on
gpt-commit-summarizer and his blog post that informed my approach.
Hero image credit to Midjourney. Prompt: “robots happily writing code”