返回顶部
g

git-commit-formatterGit提交格式化

|

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
318
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

git-commit-formatter

目标

在5秒内生成符合Conventional Commits规范的提交信息,团队间100%保持一致。



操作说明

步骤1:接收输入

检查用户提供的输入类型:

如果是Git diff输出(包含diff --git、index、带+/-的行):
→ 解析diff以提取变更信息

如果是文本描述:
→ 必要时询问澄清信息:
- 我需要了解更多:(A) 已更改的文件名,(B) 准确的变更类型,还是(C) 已更改的文件路径?

如果不明确:
→ 询问:请告诉我:(A) 使用git diff,(B) 手动描述,还是(C) 已更改的文件路径?

步骤2:确定TYPE

根据变更内容,选择合适的类型:

类型使用场景
feat新功能(新特性、新能力)
fix
修复bug(修复错误、修复bug、修复问题) |
| docs | 文档变更 |
| style | 代码格式化,不影响逻辑(空白、分号) |
| refactor | 代码重构,不改变行为(重命名、提取) |
| test | 添加、修改、重构测试 |
| chore | 维护工作(更新依赖、构建配置) |

判断逻辑:

如果包含fix + bug + error → type = fix
否则如果包含add + new + create + implement → type = feat
否则如果包含doc + readme + comment → type = docs
否则如果包含format + style + indent → type = style
否则如果包含refactor + rename + extract → type = refactor
否则如果包含test + spec + assert → type = test
否则 → type = chore

步骤3:确定SCOPE(可选)

Scope是具体的变更部分,需简洁:

如果是多个不同文件:
→ 通常使用scope(有太长风险)

如果是1个文件或1个模块:
→ 使用kebab-case格式的文件/模块名:
- auth
- user-service
- commit-formatter

步骤4:编写SUBJECT(必填)

格式:():

规则:

  • - Subject 必须包含type(小写)
  • Subject 必须包含description
  • Subject ≤ 50个字符(包括type + scope)
  • Subject 不能以句号结尾
  • Subject使用祈使语气

- ✅ Add user authentication
- ❌ Added user authentication
- ✅ Fix null pointer error
- ❌ Fixed null pointer error

示例:

feat: add user login
fix(auth): resolve session timeout
docs: update API reference
style: format code with prettier
refactor: extract validation logic
test: add unit tests for auth
chore: upgrade to Node.js v22

步骤5:编写BODY(可选)

何时需要body:

  • - 有>1个不同的变更
  • 需要解释原因(破坏性变更、边界情况)
  • 引用issue/PR

body格式:

[空行]
<解释说明>

[可选详情]

  • - Closes #123
  • Refs PR #456

body规则:

  • - subject和body之间要有1个空行
  • 每行 ≤ 72个字符(便于在终端阅读)
  • 使用与subject相同的祈使语气
  • 多个项目使用项目符号

body示例:

Add email verification flow

  • - Send verification link to user email
  • Verify token on click
  • Update user status to verified

Closes #45

步骤6:验证OUTPUT

检查刚生成的提交信息:

  • - [ ] 类型在列表中(feat|fix|docs|style|refactor|test|chore)
  • [ ] 类型为小写
  • [ ] Subject ≤ 50个字符
  • [ ] Subject包含description
  • [ ] Subject不能以句号结尾
  • [ ] 如果有body:subject/body之间有1个空行
  • [ ] Body(如果有):每行 ≤ 72个字符
  • [ ] Subject + Body使用祈使语气

如果任何检查失败 → 询问用户修改输入。



示例

示例1:正常路径 — 来自功能分支的Git diff

场景: 开发者刚完成登录功能,将代码推送到Git,需要标准提交信息。

输入(Git diff):

diff --git a/index.js b/index.js
index abc123..def456 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,6 @@
const express = require(express);
-const app = express();
+const app = express().use(express.json());

思考过程:

  • - 收到diff:添加了express.json()中间件 → 这是feat(改变了行为)
  • 文件:只有index.js → 不需要scope(如果有会太长)
  • 描述:add express json middleware → 祈使语气:add express json middleware
  • 长度:29个字符(包括feat: )< 50 ✅

输出:

feat: add express json middleware

Adds JSON body parsing to Express app.

示例2:边界情况 — 文本描述而非Git diff

场景: 开发者修复auth模块中的bug,仅用文本描述。

输入:
修复auth.js文件中session超时错误,用户10分钟后被登出

思考过程:

  • - 包含fix + error → type: fix
  • 文件:auth.js → scope: auth
  • 描述:resolve session timeout → 祈使语气 ✅
  • 长度:27个字符 < 50 ✅

输出:

fix(auth): resolve session timeout

Set session timeout to 24 hours to prevent users
from being logged out too quickly.

Closes #789

示例3:多个变更 — 更改多个不同文件

场景: 开发者重构了身份验证模块 + 修复了用户服务中的bug + 更新了这两者的文档。

输入(描述):
重构auth模块,修复用户服务验证,更新两者的文档

思考过程:

  • - 3个不同文件 → 不使用scope(太长)
  • 主要变更:重构 → type: refactor
  • 描述:refactor authentication system → 祈使语气 ✅

输出:

refactor: refactor authentication system

Extract user validation to separate service and improve
error handling across auth module.

Changes:

  • - auth.js: extract validation logic
  • user-service.js: add validation middleware
  • README.md: update auth flow docs

Refs PR #123, #456

示例4:破坏性变更 — 不兼容的更改

场景: 开发者更改了API签名,对旧客户端造成破坏性变更。

输入(描述):
更改/user端点API,从email改为userId,对客户端造成破坏性变更

思考过程:

  • - 改变了行为 → type: feat
  • 文件:user端点 → scope: user
  • 破坏性变更 → 需要body解释
  • 描述:change user endpoint to use userId → 祈使语气 ✅

输出:

feat(user): change user endpoint to use userId

BREAKING CHANGE: Email parameter removed, use userId instead.
Update API clients to use new endpoint format.

  • - Updated /user GET endpoint
  • Removed email parameter
  • Added userId parameter

Migration guide: See docs/api-migration.md

Closes #901

示例5:样式变更 — 不影响逻辑的格式化

场景: 开发者运行prettier,仅格式化代码,不改变逻辑。

输入(Git diff或描述):
用prettier格式化所有文件,添加行尾分号

思考过程:

  • - 仅格式化 → type: style
  • 文件:多个 → 不使用scope
  • 描述:format code with prettier → 祈使语气 ✅
  • 不需要body(仅格式化)

输出:

style: format code with prettier



约束条件

必须遵守(MUST)

  • - 🚫 绝对不要创建列表之外的提交类型:feat|fix|docs|style|refactor|test|chore
  • 🚫 绝对不要使用大写写type → 始终小写
  • 🚫 绝对不要让subject超过50个字符 → 截断或拆分提交
  • 🚫 绝对不要在subject末尾加句号 → 询问用户修改
  • 🚫 绝对不要缺少subject中的description → 询问用户添加
  • 始终包含type(必填)
  • 始终

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 git-commit-formatter-1776190876 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 git-commit-formatter-1776190876 技能

通过命令行安装

skillhub install git-commit-formatter-1776190876

下载

⬇ 下载 git-commit-formatter v1.0.0(免费)

文件大小: 5.83 KB | 发布时间: 2026-4-15 11:54

v1.0.0 最新 2026-4-15 11:54
Initial release: Quickly generates Conventional Commit messages from git diff or change descriptions, following strict formatting rules.

- Detects input type (git diff or text) and extracts relevant change info.
- Selects appropriate commit type (feat, fix, docs, style, refactor, test, chore) with clear mapping.
- Optionally adds scope based on file/module context.
- Enforces subject formatting: imperative mood, max 50 chars, no trailing period.
- Optionally adds body for multi-line explanations or references.
- Validates all output; prompts for corrections if guidelines are not met.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部