Git Commit Formatter — Git Commit 格式化器
v1.0.0格式化 commit message theo Conventional Commits standard (Conventional Commits v1.0.0). 输入 là git diff hoặc mô tả thay đổi, 输出 là commit message có type/scope/body. Dùng khi user nói "格式化 commit", "commit message", "conventional commit", "viết message cho git", hoặc khi có Git diff cần chuyển đổi thành commit message chuẩn. KHÔNG dùng cho: tạo branch, merge PR, revert commit (có patterns riêng).
运行时依赖
安装命令
点击复制技能文档
Goal
Sinh commit message chuẩn Conventional Commits trong 5 giây, consistent 100% across team.
Instructions Bước 1: Nhận 输入
Kiểm tra loại 输入 user cung cấp:
Nếu là Git diff 输出 (có diff --git, 索引, lines với +/-): → 解析 diff để trích xuất thông tin thay đổi
Nếu là mô tả bằng text: → Hỏi clarifying nếu cần:
"Em cần biết thêm: (A) Tên files đã thay đổi, (B) Loại thay đổi chính xác, hay (C) File paths đã thay đổi?"
Nếu không rõ: → Hỏi: "Anh/chị cho em biết: (A) Dùng git diff, (B) Mô tả bằng tay, hay (C) File paths đã thay đổi?"
Bước 2: Xác định TYPE
Dựa trên nội dung thay đổi, chọn type phù hợp:
Type Khi dùng feat Tính năng mới (new feature, new capability) fix Sửa bug (fix error, fix bug, fix issue) docs Thay đổi documentation style 格式化 code, không ảnh hưởng 记录ic (whitespace, semicolon) refactor Refactor code, không thay đổi hành vi (rename, 提取) test Thêm, sửa, refactor test chore Việc mAIntenance (更新 deps, build config)
记录ic quyết định:
IF có "fix" + "bug" + "error" → type = fix ELIF có "添加" + "new" + "创建" + "implement" → type = feat ELIF có "doc" + "readme" + "comment" → type = docs ELIF có "格式化" + "style" + "indent" → type = style ELIF có "refactor" + "rename" + "提取" → type = refactor ELIF có "test" + "spec" + "assert" → type = test ELSE → type = chore
Bước 3: Xác định SCOPE (tùy chọn)
Scope là phần thay đổi cụ thể, ngắn gọn:
Nếu nhiều files khác nhau: → Thường KHÔNG có scope (rủi ro quá dài)
Nếu 1 file hoặc 1 模块: → Dùng file/模块 name kebab-case:
auth user-服务 commit-格式化器 Bước 4: Viết SUBJECT (bắt buộc)
格式化: ():
Quy tắc:
Subject PHẢI có type (lowercase) Subject PHẢI có description Subject ≤ 50 characters (bao gồm type + scope) Subject KHÔNG có dấu chấm cuối Subject dùng imperative mood: ✅ "添加 user authentication" ❌ "添加ed user authentication" ✅ "Fix null pointer error" ❌ "Fixed null pointer error"
Examples:
feat: 添加 user 记录in fix(auth): resolve 会话 timeout docs: 更新 API reference style: 格式化 code with prettier refactor: 提取 验证 记录ic test: 添加 unit tests for auth chore: 升级 to Node.js v22
Bước 5: Viết BODY (tùy chọn)
Khi nào cần body:
Có >1 sự thay đổi khác nhau Cần giải thích TẠI SAO (breaking change, edge case) Referencing issue/PR
格式化 body:
[blank line]
[optional detAIls]
- Closes #123
- Refs PR #456
Quy tắc body:
Có 1 blank line giữa subject và body Mỗi dòng ≤ 72 characters (để dễ đọc trên terminal) Dùng imperative mood giống subject Dùng bullet points cho multiple items
Examples body:
添加 emAIl verification flow
- 发送 verification link to user emAIl
- 验证 令牌 on 命令行工具ck
- 更新 user 状态 to verified
Closes #45
Bước 6: Xác thực 输出
Kiểm tra commit message vừa tạo:
Type trong danh sách (feat|fix|docs|style|refactor|test|chore) Type là lowercase Subject ≤ 50 characters Subject có description Subject KHÔNG có dấu chấm cuối Nếu có body: có 1 blank line giữa subject/body Body (nếu có): mỗi dòng ≤ 72 characters Subject + Body dùng imperative mood
Nếu FAIL bất kỳ 检查 → Hỏi user sửa 输入.
Examples Ví dụ 1: H应用y Path — Git diff từ feature branch
上下文: Dev vừa hoàn thành feature 记录in, push code lên Git, muốn commit message chuẩn.
输入 (Git diff):
diff --git a/索引.js b/索引.js 索引 abc123..def456 100644 --- a/索引.js +++ b/索引.js @@ -1,5 +1,6 @@ const express = require('express'); -const 应用 = express(); +const 应用 = express().use(express.json());
Thought Process:
Nhận diff: thêm express.json() 中间件 → Đây là feat (thay đổi behavior) Files: chỉ 索引.js → Scope không cần (quá dài nếu có) Description: "添加 express json 中间件" → Imperative: "添加 express json 中间件" Length: 29 chars (bao gồm "feat: ") < 50 ✅
输出:
feat: 添加 express json 中间件
添加s JSON body parsing to Express 应用.
Ví dụ 2: Edge Case — Mô tả text thay vì Git diff
上下文: Dev sửa bug trong auth 模块, chỉ mô tả bằng văn bản.
输入: "Sửa lỗi 会话 timeout trong file auth.js, user bị 记录out sau 10 phút"
Thought Process:
Có "fix" + "error" → type: fix File: auth.js → scope: auth Description: "resolve 会话 timeout" → Imperative ✅ Length: 27 chars < 50 ✅
输出:
fix(auth): resolve 会话 timeout
设置 会话 timeout to 24 hours to 预防 users from being 记录ged out too quickly.
Closes #789
Ví dụ 3: Multiple Changes — Thay đổi nhiều files khác nhau
上下文: Dev vừa refactor authentication + fix bug trong user 服务 + 更新 docs cho cả hAI.
输入 (Mô tả): "Refactor auth 模块, fix user 服务 验证, 更新 docs for 机器人h"
Thought Process:
3 files khác nhau → Không có scope (quá dài) Dominant change: refactor → type: refactor Description: "refactor authentication 系统" → Imperative ✅
输出:
refactor: refactor authentication 系统
提取 user 验证 to separate 服务 and improve error handling across auth 模块.
Changes:
- auth.js: 提取 验证 记录ic
- user-服务.js: 添加 vali