Cursor 必知必会: 一键生成专业的 Git Commit Message

Authors

在我们日常的开发过程中,你是否也曾经因为填写繁琐的 Git Commit Message 而烦恼?今天,让我们一起探索如何利用 Cursor 编辑器来一键生成专业的 Git Commit Message,让你的开发过程快乐加倍。

首先,我们需要了解自上次提交以来,我们做了哪些修改。在 Cursor 中有一个命令可以通过 @Commit (Diff Of Working State) 获取修改内容,所以我们就可以通过这个命令结合提示词生成专业的 Git Commit Message:

cursorgit-rang-ni-de-0

提示词如下,提示词里面规定了 Git Commit Message 模板、提交类型的枚举以及一些其他需要注意的事项,你可以根据实际情况做一些对应的修改。

Now, please generate a commit message with Chinese.
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 and must have blank line in message template.

Below is the commit message template:

<type>(<scope>): <subject>
// blank line
<body>
// blank line
<footer>

The Header is mandatory, while the Body and Footer are optional.

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

The body section is a detailed description of this commit and can be split into multiple lines. Here's an example:

More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. 

Further paragraphs come after blank lines.

- Bullet points are okay, too
- Use a hanging indent

执行完毕后,生成的提交信息可能比你自己写的还要专业,整个过程不到 10s 。

docs(debug): 为 debug.sh 脚本添加注释

在 debug.sh 脚本中添加了中文注释,以提高脚本的可读性和可维护性。

- 为安装 dlv 的命令添加了注释
- 为启动调试的命令添加了注释

总结

本文介绍了如何利用 Cursor 编辑器和特定的提示词,生成专业的 Git 提交信息,从而大幅简化开发过程中的代码提交流程。通过使用 @Commit (Diff Of Working State) 命令,您可以轻松获取代码更改内容,并结合指定模板及提交类型枚举,快速生成符合规范的提交信息。

如果您有任何其他问题或建议,欢迎随时留言,与我们一起交流探讨!

Share this content