mcpField
G
git-commit-helper

git-commit-helper

github.com/alirezarezvani开发78239 次安装35 周前更新
代码仓库

关于 git-commit-helper

为开发者提供的 Git 提交信息生成 Skill,根据暂存区 diff 建议符合 Conventional Commits 的提交信息。支持类型、范围、主题、正文和破坏性变更说明。

主要功能

  1. 01分析暂存区 diff
  2. 02生成 Conventional Commits 格式信息
  3. 03选择提交类型与范围
  4. 04撰写主题、正文和页脚
  5. 05支持自定义类型与模板

适用场景

  1. 01提交前为暂存更改生成信息
  2. 02改进含糊或不规范的提交说明
  3. 03为团队配置提交类型和格式
  4. 04通过 prepare-commit-msg 钩子辅助提交

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/alirezarezvani/claude-code-tresor --skill git-commit-helper

安装后在 Claude Code 中输入/git-commit-helper确认已加载。

附带文件README.md

详细介绍

Git 提交助手技能

根据你的 Git 差异生成规范的提交消息。

激活时机

  • ✅ 执行 git commit 但未提供消息
  • ✅ 用户询问“我的提交消息该怎么写?”
  • ✅ 存在已暂存的更改
  • ✅ 用户提到提交或规范提交
  • ✅ 创建提交之前

生成内容

规范提交格式
<type>(<scope>): <subject>

<body>

<footer>

类型:

  • feat:新功能
  • fix:修复错误
  • docs:文档更改
  • style:代码样式(格式调整,不改变逻辑)
  • refactor:代码重构
  • perf:性能改进
  • test:新增或修复测试
  • build:构建系统更改
  • ci:CI/CD 更改
  • chore:维护任务

示例

新增功能
# You staged:
git add auth.service.ts login.component.tsx

# I analyze diff and suggest:
feat(auth): add JWT-based user authentication

- Implement login/logout functionality
- Add token management service
- Include auth guards for protected routes
- Add unit tests for auth service

Closes #42
修复错误
# You staged:
git add UserList.tsx

# I suggest:
fix(components): resolve memory leak in UserList

Fixed subscription not being cleaned up in useEffect,
causing memory leak when component unmounts.

Closes #156
重大更改
# You staged:
git add api/users.ts

# I suggest:
feat(api): update user API response format

Changed response structure to include metadata
for better pagination and filtering support.

BREAKING CHANGE: User API now returns { data, metadata }
instead of direct array. Update client code accordingly.
更新文档
# You staged:
git add README.md docs/api.md

# I suggest:
docs: update API documentation with authentication examples

- Add authentication flow diagrams
- Include cURL examples for protected endpoints
- Document error responses

分析流程

第 1 步:检查已暂存的更改
git diff --staged --name-only
git diff --staged
第 2 步:对更改分类
  • 新文件 → feat
  • 已修改文件 → fix、refactor 或 feat
  • 已删除文件 → chore 或 refactor
  • 测试文件 → test
  • 文档 → docs
第 3 步:分析内容
  • 更改了什么?
  • 为什么要更改?
  • 有什么影响?
  • 是否存在重大更改?
第 4 步:生成消息

主题行:

  • 最多 50 个字符
  • 使用祈使语气(“add”而非“added”)
  • 末尾不加句号
  • 类型后使用小写字母

正文:

  • 说明是什么以及为什么,而不是怎么做
  • 每行最多 72 个字符
  • 有多项更改时使用项目符号

页脚:

  • 重大更改:BREAKING CHANGE: description
  • 问题引用:Closes #123、Fixes #456

消息组成部分

类型选择
feat: New functionality
  - New components, features, capabilities

fix: Bug fixes
  - Resolving issues, fixing bugs

refactor: Code improvements
  - No functional changes, better code structure

perf: Performance
  - Speed improvements, optimization

docs: Documentation
  - README, comments, guides

test: Testing
  - Adding or fixing tests

style: Formatting
  - Code style, linting, formatting

chore: Maintenance
  - Dependencies, build config, tooling
作用域选择

常见作用域:

  • 组件名称:feat(UserCard): ...
  • 模块:fix(auth): ...
  • 包:chore(api): ...
  • 区域:docs(readme): ...
主题行指南

✅ 良好示例:

  • add user authentication
  • fix memory leak in component
  • update API documentation

❌ 不良示例:

  • added user authentication(过去时)
  • fixes bug(过于笼统)
  • Update API docs.(末尾有句号)

高级示例

多项更改
# Multiple files in auth feature
feat(auth): implement complete authentication system

- Add JWT token generation and validation
- Implement password hashing with bcrypt
- Create login/logout API endpoints
- Add auth middleware for protected routes
- Include refresh token functionality

Closes #42, #43, #44
重构
# Code restructuring
refactor(api): extract database logic into repository pattern

Moved database queries from controllers to repository classes
for better separation of concerns and testability.

No functional changes or API modifications.
性能改进
# Optimization
perf(queries): optimize user data fetching

- Implement query batching to eliminate N+1 queries
- Add database indices on frequently queried columns
- Cache user profile data with 5-minute TTL

Performance improvement: 80ms → 12ms average response time

Git 集成

提交前钩子

我与提交前钩子配合得很好:

#!/bin/sh
# .git/hooks/prepare-commit-msg

# If no commit message provided, trigger skill
if [ -z "$2" ]; then
  # Skill suggests message based on staged changes
  echo "# Suggested commit message (edit as needed)" > "$1"
fi
修改提交
# Poor initial message
git commit -m "fix stuff"

# Amend with better message
# I suggest improved message based on changes
git commit --amend

沙箱兼容性

无需沙箱即可运行: ✅ 是 在沙箱中运行: ✅ 是

可能需要网络访问以执行以下操作:

  • 从 GitHub API 获取问题详情
  • 检查问题编号是否有效

沙箱配置(可选):

{
  "network": {
    "allowedDomains": [
      "api.github.com"
    ]
  }
}

自定义

自定义提交类型

编辑 SKILL.md,添加公司专用类型:

deploy: Deployment
migrate: Database migrations
hotfix: Production hotfixes
自定义作用域

训练此技能识别你的项目结构:

Common scopes: auth, api, ui, database, admin, mobile
消息模板

自定义适合团队的消息格式:

# Standard format
feat(scope): subject

# Your custom format
[JIRA-123] feat(scope): subject

撰写优质消息的技巧

  1. 具体明确:“fix login button”而不是“fix bug”
  2. 使用祈使语气:“add”而不是“added”或“adds”
  3. 补充上下文:说明为何需要此更改
  4. 引用问题:始终包含问题编号
  5. 重大更改:始终在页脚中标明

常见模式

前端更改
feat(ui): add responsive navigation menu
fix(components): resolve prop validation warning
style(css): update button hover effects
后端更改
feat(api): add user pagination endpoint
fix(database): resolve connection pool exhaustion
perf(queries): add database indices for user lookups
基础设施更改
ci: add automated deployment pipeline
build: update dependencies to latest versions
chore(docker): optimize container image size

相关工具

  • code-reviewer skill:提交前审查代码
  • @docs-writer sub-agent:根据提交生成变更日志
  • /review command:提交前代码审查

集成

与 code-reviewer 集成
# 1. Write code
# 2. code-reviewer flags issues
# 3. Fix issues
# 4. Stage changes
# 5. I generate commit message
git commit  # Uses my suggested message
与 /review Command 集成
# 1. Make changes
/review --scope staged  # Review before commit
# 2. Address findings
# 3. Stage final changes
# 4. I generate commit message
git commit

了解更多

评论

支持 Markdown