docs: 将README.md翻译为中文
This commit is contained in:
148
README.md
148
README.md
@@ -3,193 +3,193 @@
|
||||
<img src=".github/screenshot.png" alt="AI Commits"/>
|
||||
<h1 align="center">AI Commits</h1>
|
||||
</div>
|
||||
<p>A CLI that writes your git commit messages for you with AI. Never write a commit message again.</p>
|
||||
<a href="https://www.npmjs.com/package/aicommits"><img src="https://img.shields.io/npm/v/aicommits" alt="Current version"></a>
|
||||
<p>一个使用 AI 为您编写 git 提交消息的 CLI 工具。再也不用手写提交消息了。</p>
|
||||
<a href="https://www.npmjs.com/package/aicommits"><img src="https://img.shields.io/npm/v/aicommits" alt="当前版本"></a>
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
## Setup
|
||||
## 设置
|
||||
|
||||
> The minimum supported version of Node.js is the latest v14. Check your Node.js version with `node --version`.
|
||||
> 支持的最低 Node.js 版本是最新的 v14。使用 `node --version` 检查您的 Node.js 版本。
|
||||
|
||||
1. Install _aicommits_:
|
||||
1. 安装 _aicommits_:
|
||||
|
||||
```sh
|
||||
npm install -g aicommits
|
||||
```
|
||||
|
||||
2. Retrieve your API key from [OpenAI](https://platform.openai.com/account/api-keys)
|
||||
2. 从 [OpenAI](https://platform.openai.com/account/api-keys) 获取您的 API 密钥
|
||||
|
||||
> Note: If you haven't already, you'll have to create an account and set up billing.
|
||||
> 注意:如果您还没有账户,您需要创建一个账户并设置计费。
|
||||
|
||||
3. Set the key so aicommits can use it:
|
||||
3. 设置密钥以便 aicommits 可以使用它:
|
||||
|
||||
```sh
|
||||
aicommits config set OPENAI_KEY=<your token>
|
||||
```
|
||||
|
||||
This will create a `.aicommits` file in your home directory.
|
||||
这将在您的主目录中创建一个 `.aicommits` 文件。
|
||||
|
||||
### Upgrading
|
||||
### 升级
|
||||
|
||||
Check the installed version with:
|
||||
使用以下命令检查已安装的版本:
|
||||
|
||||
```
|
||||
aicommits --version
|
||||
```
|
||||
|
||||
If it's not the [latest version](https://github.com/Nutlope/aicommits/releases/latest), run:
|
||||
如果它不是[最新版本](https://github.com/Nutlope/aicommits/releases/latest),请运行:
|
||||
|
||||
```sh
|
||||
npm update -g aicommits
|
||||
```
|
||||
|
||||
## Usage
|
||||
## 使用方法
|
||||
|
||||
### CLI mode
|
||||
### CLI 模式
|
||||
|
||||
You can call `aicommits` directly to generate a commit message for your staged changes:
|
||||
您可以直接调用 `aicommits` 来为您的暂存更改生成提交消息:
|
||||
|
||||
```sh
|
||||
git add <files...>
|
||||
aicommits
|
||||
```
|
||||
|
||||
`aicommits` passes down unknown flags to `git commit`, so you can pass in [`commit` flags](https://git-scm.com/docs/git-commit).
|
||||
`aicommits` 会将未知标志传递给 `git commit`,因此您可以传入 [`commit` 标志](https://git-scm.com/docs/git-commit)。
|
||||
|
||||
For example, you can stage all changes in tracked files with as you commit:
|
||||
例如,您可以在提交时暂存所有跟踪文件中的更改:
|
||||
|
||||
```sh
|
||||
aicommits --all # or -a
|
||||
aicommits --all # 或 -a
|
||||
```
|
||||
|
||||
> 👉 **Tip:** Use the `aic` alias if `aicommits` is too long for you.
|
||||
> 👉 **提示:** 如果 `aicommits` 对您来说太长,可以使用 `aic` 别名。
|
||||
|
||||
#### Generate multiple recommendations
|
||||
#### 生成多个建议
|
||||
|
||||
Sometimes the recommended commit message isn't the best so you want it to generate a few to pick from. You can generate multiple commit messages at once by passing in the `--generate <i>` flag, where 'i' is the number of generated messages:
|
||||
有时推荐的提交消息不是最好的,所以您希望它生成几个以供选择。您可以通过传入 `--generate <i>` 标志来一次生成多个提交消息,其中 'i' 是生成的消息数量:
|
||||
|
||||
```sh
|
||||
aicommits --generate <i> # or -g <i>
|
||||
aicommits --generate <i> # 或 -g <i>
|
||||
```
|
||||
|
||||
> Warning: this uses more tokens, meaning it costs more.
|
||||
> 警告:这会使用更多的令牌,意味着成本更高。
|
||||
|
||||
#### Generating Conventional Commits
|
||||
#### 生成约定式提交
|
||||
|
||||
If you'd like to generate [Conventional Commits](https://conventionalcommits.org/), you can use the `--type` flag followed by `conventional`. This will prompt `aicommits` to format the commit message according to the Conventional Commits specification:
|
||||
如果您想生成[约定式提交](https://conventionalcommits.org/),可以使用 `--type` 标志,后跟 `conventional`。这将提示 `aicommits` 根据约定式提交规范格式化提交消息:
|
||||
|
||||
```sh
|
||||
aicommits --type conventional # or -t conventional
|
||||
aicommits --type conventional # 或 -t conventional
|
||||
```
|
||||
|
||||
This feature can be useful if your project follows the Conventional Commits standard or if you're using tools that rely on this commit format.
|
||||
如果您的项目遵循约定式提交标准,或者您使用依赖此提交格式的工具,此功能会很有用。
|
||||
|
||||
### Git hook
|
||||
### Git 钩子
|
||||
|
||||
You can also integrate _aicommits_ with Git via the [`prepare-commit-msg`](https://git-scm.com/docs/githooks#_prepare_commit_msg) hook. This lets you use Git like you normally would, and edit the commit message before committing.
|
||||
您还可以通过 [`prepare-commit-msg`](https://git-scm.com/docs/githooks#_prepare_commit_msg) 钩子将 _aicommits_ 与 Git 集成。这让您可以像平常一样使用 Git,并在提交之前编辑提交消息。
|
||||
|
||||
#### Install
|
||||
#### 安装
|
||||
|
||||
In the Git repository you want to install the hook in:
|
||||
在您要安装钩子的 Git 仓库中:
|
||||
|
||||
```sh
|
||||
aicommits hook install
|
||||
```
|
||||
|
||||
#### Uninstall
|
||||
#### 卸载
|
||||
|
||||
In the Git repository you want to uninstall the hook from:
|
||||
在您要卸载钩子的 Git 仓库中:
|
||||
|
||||
```sh
|
||||
aicommits hook uninstall
|
||||
```
|
||||
|
||||
#### Usage
|
||||
#### 使用方法
|
||||
|
||||
1. Stage your files and commit:
|
||||
1. 暂存您的文件并提交:
|
||||
|
||||
```sh
|
||||
git add <files...>
|
||||
git commit # Only generates a message when it's not passed in
|
||||
git commit # 仅在未传入消息时生成消息
|
||||
```
|
||||
|
||||
> If you ever want to write your own message instead of generating one, you can simply pass one in: `git commit -m "My message"`
|
||||
> 如果您想自己编写消息而不是生成消息,可以简单地传入一个:`git commit -m "My message"`
|
||||
|
||||
2. Aicommits will generate the commit message for you and pass it back to Git. Git will open it with the [configured editor](https://docs.github.com/en/get-started/getting-started-with-git/associating-text-editors-with-git) for you to review/edit it.
|
||||
2. Aicommits 将为您生成提交消息并将其传递回 Git。Git 将使用[配置的编辑器](https://docs.github.com/en/get-started/getting-started-with-git/associating-text-editors-with-git)打开它供您查看/编辑。
|
||||
|
||||
3. Save and close the editor to commit!
|
||||
3. 保存并关闭编辑器以提交!
|
||||
|
||||
## Configuration
|
||||
## 配置
|
||||
|
||||
### Reading a configuration value
|
||||
### 读取配置值
|
||||
|
||||
To retrieve a configuration option, use the command:
|
||||
要检索配置选项,请使用命令:
|
||||
|
||||
```sh
|
||||
aicommits config get <key>
|
||||
```
|
||||
|
||||
For example, to retrieve the API key, you can use:
|
||||
例如,要检索 API 密钥,您可以使用:
|
||||
|
||||
```sh
|
||||
aicommits config get OPENAI_KEY
|
||||
```
|
||||
|
||||
You can also retrieve multiple configuration options at once by separating them with spaces:
|
||||
您还可以通过用空格分隔它们来一次检索多个配置选项:
|
||||
|
||||
```sh
|
||||
aicommits config get OPENAI_KEY generate
|
||||
```
|
||||
|
||||
### Setting a configuration value
|
||||
### 设置配置值
|
||||
|
||||
To set a configuration option, use the command:
|
||||
要设置配置选项,请使用命令:
|
||||
|
||||
```sh
|
||||
aicommits config set <key>=<value>
|
||||
```
|
||||
|
||||
For example, to set the API key, you can use:
|
||||
例如,要设置 API 密钥,您可以使用:
|
||||
|
||||
```sh
|
||||
aicommits config set OPENAI_KEY=<your-api-key>
|
||||
```
|
||||
|
||||
You can also set multiple configuration options at once by separating them with spaces, like
|
||||
您还可以通过用空格分隔它们来一次设置多个配置选项,例如
|
||||
|
||||
```sh
|
||||
aicommits config set OPENAI_KEY=<your-api-key> generate=3 locale=en
|
||||
```
|
||||
|
||||
### Options
|
||||
### 选项
|
||||
|
||||
#### OPENAI_KEY
|
||||
|
||||
Required
|
||||
必需
|
||||
|
||||
The OpenAI API key. You can retrieve it from [OpenAI API Keys page](https://platform.openai.com/account/api-keys).
|
||||
OpenAI API 密钥。您可以从 [OpenAI API 密钥页面](https://platform.openai.com/account/api-keys) 检索它。
|
||||
|
||||
#### locale
|
||||
|
||||
Default: `en`
|
||||
默认值:`en`
|
||||
|
||||
The locale to use for the generated commit messages. Consult the list of codes in: https://wikipedia.org/wiki/List_of_ISO_639-1_codes.
|
||||
用于生成提交消息的语言环境。请参阅以下列表中的代码:https://wikipedia.org/wiki/List_of_ISO_639-1_codes。
|
||||
|
||||
#### generate
|
||||
|
||||
Default: `1`
|
||||
默认值:`1`
|
||||
|
||||
The number of commit messages to generate to pick from.
|
||||
要生成的提交消息数量以供选择。
|
||||
|
||||
Note, this will use more tokens as it generates more results.
|
||||
注意,这会使用更多的令牌,因为它会生成更多的结果。
|
||||
|
||||
#### proxy
|
||||
|
||||
Set a HTTP/HTTPS proxy to use for requests.
|
||||
设置用于请求的 HTTP/HTTPS 代理。
|
||||
|
||||
To clear the proxy option, you can use the command (note the empty value after the equals sign):
|
||||
要清除代理选项,您可以使用命令(注意等号后的空值):
|
||||
|
||||
```sh
|
||||
aicommits config set proxy=
|
||||
@@ -197,17 +197,17 @@ aicommits config set proxy=
|
||||
|
||||
#### model
|
||||
|
||||
Default: `gpt-3.5-turbo`
|
||||
默认值:`gpt-3.5-turbo`
|
||||
|
||||
The Chat Completions (`/v1/chat/completions`) model to use. Consult the list of models available in the [OpenAI Documentation](https://platform.openai.com/docs/models/model-endpoint-compatibility).
|
||||
要使用的聊天完成(`/v1/chat/completions`)模型。请参阅 [OpenAI 文档](https://platform.openai.com/docs/models/model-endpoint-compatibility)中可用模型的列表。
|
||||
|
||||
> Tip: If you have access, try upgrading to [`gpt-4`](https://platform.openai.com/docs/models/gpt-4) for next-level code analysis. It can handle double the input size, but comes at a higher cost. Check out OpenAI's website to learn more.
|
||||
> 提示:如果您有权限,尝试升级到 [`gpt-4`](https://platform.openai.com/docs/models/gpt-4) 以获得更高级的代码分析。它可以处理双倍的输入大小,但成本更高。请访问 OpenAI 的网站了解更多信息。
|
||||
|
||||
#### timeout
|
||||
|
||||
The timeout for network requests to the OpenAI API in milliseconds.
|
||||
向 OpenAI API 发出网络请求的超时时间(以毫秒为单位)。
|
||||
|
||||
Default: `10000` (10 seconds)
|
||||
默认值:`10000`(10 秒)
|
||||
|
||||
```sh
|
||||
aicommits config set timeout=20000 # 20s
|
||||
@@ -215,9 +215,9 @@ aicommits config set timeout=20000 # 20s
|
||||
|
||||
#### max-length
|
||||
|
||||
The maximum character length of the generated commit message.
|
||||
生成的提交消息的最大字符长度。
|
||||
|
||||
Default: `50`
|
||||
默认值:`50`
|
||||
|
||||
```sh
|
||||
aicommits config set max-length=100
|
||||
@@ -225,32 +225,32 @@ aicommits config set max-length=100
|
||||
|
||||
#### type
|
||||
|
||||
Default: `""` (Empty string)
|
||||
默认值:`""`(空字符串)
|
||||
|
||||
The type of commit message to generate. Set this to "conventional" to generate commit messages that follow the Conventional Commits specification:
|
||||
要生成的提交消息类型。将其设置为 "conventional" 以生成遵循约定式提交规范的提交消息:
|
||||
|
||||
```sh
|
||||
aicommits config set type=conventional
|
||||
```
|
||||
|
||||
You can clear this option by setting it to an empty string:
|
||||
您可以通过将其设置为空字符串来清除此选项:
|
||||
|
||||
```sh
|
||||
aicommits config set type=
|
||||
```
|
||||
|
||||
## How it works
|
||||
## 工作原理
|
||||
|
||||
This CLI tool runs `git diff` to grab all your latest code changes, sends them to OpenAI's GPT-3, then returns the AI generated commit message.
|
||||
这个 CLI 工具运行 `git diff` 来获取您所有的最新代码更改,将它们发送到 OpenAI 的 GPT-3,然后返回 AI 生成的提交消息。
|
||||
|
||||
Video coming soon where I rebuild it from scratch to show you how to easily build your own CLI tools powered by AI.
|
||||
视频即将推出,我将从头开始重建它,向您展示如何轻松构建由 AI 驱动的自己的 CLI 工具。
|
||||
|
||||
## Maintainers
|
||||
## 维护者
|
||||
|
||||
- **Hassan El Mghari**: [@Nutlope](https://github.com/Nutlope) [<img src="https://img.shields.io/twitter/follow/nutlope?style=flat&label=nutlope&logo=twitter&color=0bf&logoColor=fff" align="center">](https://twitter.com/nutlope)
|
||||
|
||||
- **Hiroki Osame**: [@privatenumber](https://github.com/privatenumber) [<img src="https://img.shields.io/twitter/follow/privatenumbr?style=flat&label=privatenumbr&logo=twitter&color=0bf&logoColor=fff" align="center">](https://twitter.com/privatenumbr)
|
||||
|
||||
## Contributing
|
||||
## 贡献
|
||||
|
||||
If you want to help fix a bug or implement a feature in [Issues](https://github.com/Nutlope/aicommits/issues), checkout the [Contribution Guide](CONTRIBUTING.md) to learn how to setup and test the project
|
||||
如果您想在 [Issues](https://github.com/Nutlope/aicommits/issues) 中帮助修复错误或实现功能,请查看 [贡献指南](CONTRIBUTING.md) 以了解如何设置和测试项目。
|
||||
|
||||
Reference in New Issue
Block a user