让 Cursor AI 帮忙写 git commit message

不是不想写 commit message,而是每次审阅代码+组织语言去准确描述比较难,耗费精力和时间。
让 Cursor AI 来辅助撰写,提高效率,也学习如何用 Commits 规范和英文去总结和表达。

Cursor v0.43 版本已支持直接在 git 面板一键生成 commit message。 (2024-12-03)

自定义提示词:

copy from: https://gist.github.com/yan5xu/97a844640b52f6bf1a2f06751cc36257

根据 @git-changes 提交 git
遵循 Angular Commit Message 规范
"""
格式:
<type>(<scope>): <subject>

<body>

<footer>

其中 subject 必填,body 和 footer 可选

type: feat|fix|docs|style|refactor|test|chore|perf
scope: 可选,表示影响范围(如模块名)
subject: 简明扼要的提交说明
body: 详细描述,可多行
footer: 通常用于关联 Issue 或破坏性变更说明

示例:
feat(auth): 添加微信登录功能

- 支持微信扫码登录
- 支持微信账号绑定
- 添加微信用户信息同步

Closes #123
"""

以下是 Cursor v0.42 及以前版本的方法:

打开 Composer 或 Chat 窗口, @Commit (Diff of Working State)
输入提示词:

write a commit message for changed code with English.

回车提交。

Claude-3.5-sonet 会遵循 Commits 规范写一份 commit message。

注:若已修改的代码中,有不想让AI审阅并写 commit message 的部分,可以提交到暂存更改区(git add)。

另附:可自定义详细的指引提示词。例如在使用其它模型时,可能需要更详细的规范指导:

Please generate a commit message with English.
Make sure it includes an accurate and informative subject line that
succinctly summarizes the key points of the changes, the response must only have commit message content.

Below is the commit message template:

<type>(<scope>): <subject>

Regardless of which part, no line should exceed 72 characters (or 100 characters). This is to avoid automatic Line breaks affecting aesthetics.

Below is the type Enum:

- feat: new feature
- fix: bug fix
- docs: documentation
- style: formatting (changes that do not affect code execution)
- refactor: refactoring (code changes that are neither new features nor bug fixes)
- test: adding tests
- chore: changes to the build process or auxiliary tools