banner
Bai

Bai

写代码菜的一批 🤣
twitter
telegram
tg_channel
pixiv
github
bilibili
whatsapp

Improving Git workflow: Writing more natural commit messages using Gptcommit.

Gptcommit is a Git commit message generation tool based on the natural language generation model GPT. It can help developers write Git commit messages in a more natural way, thereby improving code readability and maintainability. In this article, we will introduce how to install and use Gptcommit.

Official Demo#

asciicast

Installation#

Installing Gptcommit is very simple, you just need to follow the steps below.

  1. Local installation

Gptcommit is a Rust application, so you need to install the Rust toolchain first. You can download and install Rust from the Rust official website. Once the Rust toolchain is installed, you can use the Cargo command to install Gptcommit. Enter the following command in the terminal or command prompt:

cargo install --locked gptcommit

This command will download the source code of Gptcommit and build the executable file. After the build is completed, Gptcommit will be installed in your system's default path.

Installation on macOS

brew install zurawiki/brews/gptcommit
  1. In your git repository, run the following command to install gptcommit as the git prepare-commit-msg hook. You need to provide the OpenAI API key to complete the installation.
gptcommit install

If you encounter any installation issues, please refer to the Gptcommit official documentation for more information.

Usage#

To use gptcommit, simply run git commit as usual. The hook will automatically generate commit messages for you using large language models like GPT. If you are not satisfied with the generated message, you can edit it at any time before committing.

Note: By default, gptcommit uses the GPT-3 model. Make sure you have enough credit in your OpenAI account to use it.

Set OpenAI API Key and URL#

  1. Global settings
#api
gptcommit config set openai.api_key sk-...
#url
gptcommit config set openai.api_base https://...
  1. Repo-specific settings
#api
gptcommit config set --local openai.api_key sk-...
#url
gptcommit config set --local openai.api_base https://...

Set commit language#

The default language is en (English), but you can set the language yourself.

gptcommit config set output.lang zh-cn

Supported languages:

codelanguage
enEnglish
zh-cnSimplified Chinese
zh-twTraditional Chinese
jaJapanese

Gptcommit also has many other features and options that you can view by entering the following command:

gptcommit --help

This command will display the help information of Gptcommit, which includes detailed information on how to use content, control the length of generated messages, and set default configurations.

Advantages#

One of the main advantages of using Gptcommit is that it can reduce the time and effort required for manually inputting commit messages. Compared to manually writing commit messages, Gptcommit can greatly shorten the time to write commit messages and ensure that each commit message complies with grammatical rules. Additionally, since Gptcommit generates readable and understandable commit messages, it can also improve code readability and maintainability.

Furthermore, Gptcommit is based on the powerful natural language generation model GPT, so it can generate high-quality natural language text. Whether it is writing commit messages or other text content, Gptcommit can provide useful assistance.

Derived Projects#

vscode-gptcommit is a plugin for automated git commit using the GPT model through VS Code's gptcommit.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.