跳到正文
Skillpedia
通用编程33k · #8853

commit-smart

它能做什么

这项技能帮你的智能体依据实际代码改动编写 git 提交信息。适合希望提交历史一致且有意义的开发者。

适用场景

  • ✓当你的改动已经准备好,并希望为它编写清晰的提交信息时。
  • ✓当你想遵循 Conventional Commit 格式,又不想记住规则时。
  • ✓当你想把相关文件归入合理的提交中的时候。

技能链接

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/git/commit-smart/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/git/commit-smart/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请查看我已暂存的改动,并按 Conventional Commit 格式写一条说明我为什么这样改的提交信息。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会检查 git 状态和暂存差异,根据修改的文件选择提交类型和范围,并写出以改动原因为重点的信息。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Smart Commit

Create meaningful conventional commits by analyzing your actual changes.

Workflow

Step 1: Assess the working tree

Run these commands to understand the current state:

git status
git diff --stat
git diff --cached --stat

Step 2: Handle unstaged changes

If nothing is staged (git diff --cached is empty):

  1. Show the user what files have changed
  2. Suggest what to stage based on logical grouping (e.g., "these 3 files are all related to the auth refactor")
  3. Ask if they want to stage all, or select specific files
  4. Stage the approved files with git add <files>

If changes are already staged, proceed to analysis.

Step 3: Analyze the diff

Read the full staged diff:

git diff --cached

Determine the commit type from the changes:

Signal Type
New files with new functionality feat
New test files or test additions test
Changes to existing logic fixing incorrect behavior fix
Structural changes without behavior change refactor
package.json, tsconfig, CI config changes chore
Build/bundler config changes build
README, docs, comments only docs
Formatting, whitespace, semicolons only style
Performance improvements perf

Determine the scope from the primary directory or module affected:

  • src/api/ -> api
  • src/components/auth/ -> auth
  • tests/ -> tests
  • Root config files -> omit scope
  • Multiple unrelated areas -> omit scope

Step 4: Check for user overrides

If the user provided arguments via $ARGUMENTS:

  • Single word (e.g., fix) -> use as commit type
  • Two words (e.g., refactor api) -> use as type and scope
  • Otherwise -> use auto-detected values

Step 5: Compose the commit message

Format: type(scope): imperative short description

Rules:

  • Subject line max 72 characters
  • Use imperative mood ("add", "fix", "refactor", not "added", "fixes")
  • Don't end with a period
  • Body explains WHY this change was made, not what changed (the diff shows what)
  • If changes are trivial (typo fix, formatting), skip the body

Example:

feat(auth): add JWT refresh token rotation

Tokens were expiring mid-session for users with slow connections.
Rotating refresh tokens extends the session without compromising
security, since each refresh token can only be used once.

Step 6: Confirm and commit

Show the user the proposed commit message and ask for confirmation.

If confirmed, run:

git commit -m "<message>"

Then verify with:

git log --oneline -1

Show the committed hash and message.

Tips

  • Run after completing a logical unit of work, not after every file change
  • If the diff is too large for one commit, suggest splitting into multiple commits
  • For breaking changes, add ! after the scope: feat(api)!: change response format
  • The body should answer "if someone reads this commit in 6 months, will they understand WHY?"
常见问题

什么是 Conventional Commit?

它是一种标准的提交信息格式,以类型开头,例如 feat 或 fix,后面可以带范围。

如果什么都没有暂存怎么办?

这项技能会列出改动的文件,建议合理的分组,并询问你要暂存哪些文件。

我能自己选择类型吗?

可以。你可以指定类型和范围,例如 fix 或 refactor api,来引导提交信息。

详情

作者的原始描述

Analyze staged/unstaged changes and create semantic conventional commits with context about WHY, not just WHAT. Auto-detects commit type and scope from the diff. Supports optional type/scope arguments. Usage - /commit-smart, /commit-smart fix, /commit-smart refactor api

repo: davila7/claude-code-templates

热度

GitHub 星标
33k
排名
#8853
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能