はじめに
AI に職を奪われることを危惧している紳士諸君も、AI を使いこなせなければ確かに食べていけなくなるかもしれない。
そんな中、git の commit message を手動で入力するのはアホらしくありませんか?
だって、要約を得意とする生成 AI があるのに、わざわざ自分で内容を要約した一文、ないしいくつかのメッセージを自分で考えるんですよ?
それは AI にやらせましょう。ai-commit にやらせましょう。
ai-commit
2025/02/23時点でググって上位に出るこれです。
https://github.com/insulineru/ai-commit
npm でインストールし、OpenAI の API Key をセットし、あとは使うだけの代物です。
1
2
3
|
$ npm install -g ai-commit
added 109 packages in 21s
|
OpenAI API Key の発行は、ログイン状態で下記のリンクを踏んでください。
https://platform.openai.com/account/api-keys
.bash_profile あたりに環境変数をセットください。
早速、今は Hugoの初期生成した hello-world.md を書き換えてこの記事の内容にしていますので、これを ai-commit にやってもらいます。
僕が commit message を書くなら、以下の感じです。
- rename hello-world.md to ai-commit.md
- change its content from greeting to ai-commit testing
そして結果は以下の通りです。
1
2
3
|
$ ai-commit
No changes to commit 🙅
May be you forgot to add the files? Try git add . and then run this script again.
|
ステージングし忘れてました。
気を取り直してもう一度。
1
2
3
4
5
6
7
8
9
10
|
$ ai-commit
file:///home/xxx/.nvm/versions/node/v22.12.0/lib/node_modules/ai-commit/node_modules/chatgpt/build/index.js:307
const error = new ChatGPTError(msg, { cause: res });
^
ChatGPTError: OpenAI error 429: {
"error": {
"message": "You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.",
"type": "insufficient_quota",
...
|
未入金でした。OpenAI の API を使うには、最低でも 5 ドルの入金が必要です。
5 ドルの入金後に気づいたのですが、過去別のアカウントで 5 ドル入金していました。
そのアカウントの残高を見ると、すでに 0 でしたが。有効期限が切れたようです。お金の有効期限・・・。
強く気を取り直して、以下が ai-commit によるコミットメッセージです。
1
2
3
4
5
6
7
8
|
$ ai-commit
Proposed Commit:
------------------------------
♻️ refactor: rename hello-world.md to ai-commit.md and change its content to focus on AI commit messages with ai-commit.
------------------------------
? Do you want to continue? Yes
Committing Message... 🚀
Commit Successful! 🎉
|
よくないですね。
実は、この時点ではファイル名は hello-world.md のままでした。
なので、この記事本文の情報からコミットメッセージを要約してはいるものの、変更を正しく把握できてませんね。
以下の git status の状態で ai-commit を実行します。
1
2
3
4
5
6
7
8
9
|
$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: ai-commit-intro.md
deleted: hello-world.md
|
一応、--list オプションと --language japanese オプションを使って 5 つの選択肢から最善のものを選んだのですが、以下の通りでした。
1
2
3
4
|
$ ai-commit --list --language japanese
? Select a commit message 📝 docs: Update instructions for setting OpenAI API Key
Committing Message... 🚀
Commit Successful! 🎉
|
どういうプロンプトが発行されているか気になった人は GitHub を覗いてみてください。
https://github.com/insulineru/ai-commit/blob/main/openai.js#L27
あまり洗練されているようには思えませんね。
改善してほしい点
- 日本語に対応してほしい
- 生成されたコミットメッセージがいまいちなとき、コミットを中止できるようにしてほしい(Ctrl + C せざるを得ない)
- Conventional commit に対応してほしい
- プロンプトに埋め込む変数を設定ファイル上で設定させてほしい
他の AI commit message generator を使ってみるとしましょう。
事後談
AI コミットの Zenn 記事に比較があったので、その中から現在スター数の最も多い aicommitsを使ってみたところ、サイコーでした。
※最初の ai-commit はスター数 366, aicommits は 8.3k
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
$ aicommits
┌ aicommits
│
◇ Detected 1 staged file:
hugo.toml
│
◇ Changes analyzed
│
◇ Use this commit message?
Update title in hugo.toml to remove unnecessary apostrophe
│ Yes
│
└ ✔ Successfully committed!
|