2 个稳定版本

1.0.1 2023 年 7 月 19 日
1.0.0 2023 年 7 月 18 日

#2947命令行工具

MIT 许可证

21KB
130 代码行

Commit GPT

使用 ChatGPT 为您暂存(但未推送)的提交生成提交信息。

先决条件

  1. 创建账户 & 为 OpenAI 生成 API 密钥.
  2. 将您的 API 密钥添加为环境变量
     export OPENAI_API_KEY='sk-...'
    

安装

$ cargo install commit-gpt

用法

-- Stage your changes
$ git add -A
$ commit-gpt
-- Commit message will be printed, as such:
$ COMMIT MESSAGE: Update README.md with instructions..
-- It will also be copied to your clipboard, so you can just paste.
$ git commit -m "..."

选项

  -p, --prompt <PROMPT>  The prompt to use when generating the commit message [default: "Generate a Git commit message based on the following diff:"]
  -m, --model <MODEL>    Which GPT model to use [default: gpt4] [possible values: gpt4, gpt35]
  -t, --tokens <TOKENS>  The maximum amount of tokens to generate. Tokens as pieces of words, where 1,000 tokens is about 750 words [default: 512]
  -h, --help             Print help
  -V, --version          Print version
  • GPT 4 的表现比 GPT 3.5 更好,因此我建议坚持使用默认设置。
  • 由于您按令牌计费,所以在增加 tokens 参数时要小心。我建议设置一个 使用限制 以确保。

调整提示

我建议您根据需要调整提示。默认提示对简单的提交来说很好,但对于更大更重要的情况,您可以通过一些简单的调整大大改善提交信息。

一些提示及其结果

  • 根据以下 diff 生成 Git 提交信息:(默认提示)
COMMIT MESSAGE: "Add new testing configuration and invert_color function in shade_generator module"
  • 生成 Git 提交信息,提供对更改的上下文,基于以下 diff:
COMMIT MESSAGE: "Added testing environment configuration and color inversion function
This update involves two key changes to the shade_generator. Firstly, a config.toml file was added with the inclusion of a testing environment attribute set to true. This initiates the setup for testing and debugging of shade_generator functions. Secondly, color inversion functionality is now introduced to the generator.py script. This new method, invert_color, will allow the inversion of given color, which can improve color efficiency and variety in the shade generation process."
  • 生成 Git 提交信息,提供作为尽可能多的作为细节,基于以下 diff:
COMMIT MESSAGE: "Added testing environment variable and color inversion function

This commit introduces a couple of significant changes. 
Firstly, a new file named config.toml has been added to the shade_generator directory. This file contains a new environment variable setting (env), defined for testing purposes. This suggests that any code that uses this environment variable will switch to a testing mode when the 'testing' variable is set to true. 
Secondly, in the generator.py file within the shade_generator directory, a new function named 'invert_color' has been added. While the implementation of this function is not complete in the diff provided, it seems like it will take a color and output another color, presumably being the inverse of the input. Two new variables, avc and vde, have been declared in this function, but their purpose is not explicit from the diff.
This commit is intended to enhance the functionality of the shade_generator tool by adding a potential for testing and the starting functionality for color inversion.

  • 生成 Git 提交信息15 世纪诗歌的风格中,基于以下 diff:
COMMIT MESSAGE: "From nought to song, config.toml now exists,
With [env] testing = true midst its lists.
Shade generator, too, hath been revised,
An invert color method is devised.
True work is done, yet not with testing ends,
The cause of hues to 'gainst their nature bend.
Doth make our colors dance a contrary turn,
Appear they will as invert, concern.
To the labor of scripting, I hath thee invite,
Run the tests, ensure all execute right."
  • 生成 Git 提交信息Linus Torvalds 的风格中,基于以下 diff:
COMMIT MESSAGE: "Commit new test environment config and add color inversion function
I've added a file for us to manage our config settings in, with a testing flag to boot. 
But wait, there's more! It seems that the shade generator was seriously lacking some functionality. Lo and behold, the invert_color function. I bet you didn't think we'd need that! Now color inversion is as easy as calling a function. 
Don't ask me what those magic numbers are, they're probably very important."

依赖项

~10–26MB
~415K SLoC