commit-detection

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Commit Type Detection Skill

提交类型检测技能

Expert knowledge for detecting the optimal conventional commit type.
具备检测最优规范提交类型的专业知识。

Detection Algorithm

检测算法

Step 1: Gather Data

步骤1:收集数据

bash
undefined
bash
undefined

Get modified files

获取修改的文件

git diff --name-only git diff --staged --name-only
git diff --name-only git diff --staged --name-only

Get change statistics

获取变更统计信息

git diff --stat git diff --staged --stat
git diff --stat git diff --staged --stat

Check for keywords in diff

在差异中查找关键词

git diff | grep -i "fix|bug|error" | head -5
undefined
git diff | grep -i "fix|bug|error" | head -5
undefined

Step 2: Categorize Files

步骤2:文件分类

CategoryFile Patterns
docs
*.md
,
*.txt
,
*.rst
,
README*
,
CHANGELOG*
test
*.test.*
,
*.spec.*
,
__tests__/*
,
test/*
config
*.json
,
*.yml
,
*.yaml
,
*.toml
,
.*rc
ci
.github/*
,
.gitlab-ci.yml
,
Jenkinsfile
build
package.json
,
Makefile
,
webpack.*
,
vite.*
styleOnly whitespace, formatting changes
src
*.ts
,
*.js
,
*.py
,
*.go
,
*.rs
, etc.
类别文件模式
文档
*.md
,
*.txt
,
*.rst
,
README*
,
CHANGELOG*
测试
*.test.*
,
*.spec.*
,
__tests__/*
,
test/*
配置
*.json
,
*.yml
,
*.yaml
,
*.toml
,
.*rc
CI
.github/*
,
.gitlab-ci.yml
,
Jenkinsfile
构建
package.json
,
Makefile
,
webpack.*
,
vite.*
格式仅空白字符、格式变更
源码
*.ts
,
*.js
,
*.py
,
*.go
,
*.rs

Step 3: Apply Rules

步骤3:应用规则

IF only docs files changed:
  → docs

IF only test files changed:
  → test

IF only config/build files changed:
  → chore

IF only CI files changed:
  → ci

IF diff contains "fix", "bug", "error", "issue", "resolve":
  → fix

IF new files added with business logic:
  → feat

IF files renamed/moved without logic change:
  → refactor

IF performance keywords ("optimize", "perf", "speed", "cache"):
  → perf

IF formatting only (whitespace, semicolons):
  → style

DEFAULT:
  → Use /commit-pro:commit for smart analysis
如果仅文档文件变更:
  → docs

如果仅测试文件变更:
  → test

如果仅配置/构建文件变更:
  → chore

如果仅CI文件变更:
  → ci

如果差异中包含"fix"、"bug"、"error"、"issue"、"resolve":
  → fix

如果添加了包含业务逻辑的新文件:
  → feat

如果文件重命名/移动但未修改逻辑:
  → refactor

如果包含性能相关关键词("optimize"、"perf"、"speed"、"cache"):
  → perf

如果仅涉及格式调整(空白字符、分号):
  → style

默认:
  → 使用 /commit-pro:commit 进行智能分析

Step 4: Determine Scope

步骤4:确定范围

Extract scope from primary directory:
src/components/Button.tsx → ui or button
src/api/auth.ts → auth
lib/utils/date.ts → utils
server/routes/user.ts → user
从主目录提取范围:
src/components/Button.tsx → ui 或 button
src/api/auth.ts → auth
lib/utils/date.ts → utils
server/routes/user.ts → user

Quick Reference

快速参考

TypeWhen
feat
New functionality
fix
Bug correction
docs
Documentation only
style
Formatting only
refactor
Code restructure
perf
Performance
test
Tests only
build
Build/deps
ci
CI/CD config
chore
Maintenance
类型适用场景
feat
新增功能
fix
修复Bug
docs
仅文档变更
style
仅格式调整
refactor
代码重构
perf
性能优化
test
仅测试文件变更
build
构建/依赖变更
ci
CI/CD配置变更
chore
日常维护

Examples

示例

Example 1: Only README changed
Files: README.md
→ /commit-pro:docs
Example 2: New component + test
Files: src/Button.tsx, src/Button.test.tsx
→ /commit-pro:feat (primary is new feature)
Example 3: Fix in existing file
Files: src/api/auth.ts
Diff contains: "fix login bug"
→ /commit-pro:fix
示例1:仅README文件变更
文件:README.md
→ /commit-pro:docs
示例2:新增组件+测试文件
文件:src/Button.tsx, src/Button.test.tsx
→ /commit-pro:feat(主要为新增功能)
示例3:修复现有文件中的问题
文件:src/api/auth.ts
差异内容包含:"fix login bug"
→ /commit-pro:fix