使用 AI 生成 commit message

因为自己也用两个月了,这期间基本不太手动写 commit message ,觉得用着还不错所以想分享一下

代码基本上都是 AI 写的(README 也是

在此之前也尝试使用过 magit-gptcommit,不过这个包我安装完之后没办法开箱即用,加上他后来把 gptel 改成 llm 就没有再用了,而且当时 AI 上下还不是太长,如果文件改动的多可能还要考虑如何处理

其次是在使用 AI 生成 commit message 的时候发现如果直接生成的话 AI 可能只是 ‘描述’ 了代码都改了什么,但是为什么这样改只能人为的告诉 AI,这也是我添加了 gptel-commit-rationale 这个函数的原因,可以方便的完成这个动作

5 个赞

Ellama也可以直接使用。

但是,根据我的经验,仍然需要大量编辑提交信息。

1 个赞

没有用过 ellama,不过我尽量让我配置中 AI 相关的配置只依赖 gptel 一个底层

其次我只是想生成个 commit message, ellama 那一堆文档和函数。。

这个包挺方便的 想请教如何让它每次生成一行的commit msg? 现在经常生成多行 有点长

改一下 prompt

能给个推荐的prompt吗 如果您是maintainer 您比我在这个问题上专业多了

我不专业哈哈哈哈/(ㄒoㄒ)/~~ 也是边改边试慢慢抽奖

这是我让 claude 改了下 zed 的 prompt,你可以试一下,如果还会生成 body 就让 AI 重写的限制更严格点

You are an expert at writing Git commits. Your job is to write a short clear commit message that summarizes the changes.

Write only a subject line - do not include a message body.

Only return the commit message in your response. Do not include any additional meta-commentary about the task. Do not include the raw diff output in the commit message.

Follow good Git style:

- Try to limit the subject line to 50 characters
- Capitalize the subject line  
- Do not end the subject line with any punctuation
- Use the imperative mood in the subject line
1 个赞

不过你也可以手动写个函数加到 hook 里把 body 删掉。。不过这样有点多此一举没什么必要了,感觉会损失一点信息,如果能改 prompt 让 AI 只生成一行是最简单有效的了