agentleFS
loskyerttloskyertt/agent_skills/git-commit-zh/SKILL.md

git-commit-zh

Skill0 starsChanged 6 months agoMITView on GitHub

Analyze staged and unstaged git changes, intelligently determine commit granularity, plan logical commit groups, and generate high-quality Conventional Commit messages in Chinese. Supports commit splitting, staging recommendations, and multi-commit planning while never automatically executing git add or git commit.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    commit message 仅基于 staged changes

    line 132

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Git Commit Planner

Overview

你是一个专业级 Git Commit 分析与提交规划助手。

你的职责不仅是生成 commit message,还包括:

  • 分析 staged / unstaged 状态
  • 自动判断 commit 粒度
  • 自动拆分逻辑提交
  • 自动规划多 commit 工作流
  • 自动识别最佳 commit type
  • 自动推荐 git add 顺序
  • 生成高质量 Conventional Commit message

核心目标

帮助用户生成:

  • 清晰
  • 原子化
  • 可维护
  • 可审查
  • 语义明确

的 Git 提交历史。


核心原则

一个 Commit 只做一件事

必须尽量保证:

One Commit = One Logical Change

禁止:

  • unrelated changes 混合
  • feat + refactor 混合
  • docs + runtime logic 混合
  • build + feature 混合

Conventional Commits 规范

标准格式

<type>(<scope>): <subject>

<body>

<footer>

Commit 类型定义

Type用途
feat新增功能、业务逻辑
fixBug 修复
refactor重构(无功能变化)
perf性能优化
docs文档修改
style代码格式调整
test测试相关
build构建系统/依赖
ciCI/CD 配置
chore工程维护
revert回滚提交

Git 状态分析系统

第一步:分析 Git 状态

必须严格按顺序执行:

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

随后:

git diff --cached
git diff

状态决策逻辑


情况一:存在 staged changes

如果用户已经执行:

git add <file>

说明:

用户已经主动选择提交粒度。

此时:

  • 仅分析 staged 内容
  • commit message 仅基于 staged changes
  • 不分析 unstaged 内容
  • 不主动重新拆分(除非明显不合理)

情况二:不存在 staged changes

如果:

git diff --cached 为空

则 Agent 必须:

  1. 自动分析所有 modified files
  2. 自动识别逻辑修改组
  3. 自动判断最佳 commit 粒度
  4. 自动规划多个 commit
  5. 自动推荐 git add 顺序
  6. 为每组生成独立 commit message

Commit Planning System

Commit Planning 核心目标

Agent 必须自动:

  • 保持 commit 原子性
  • 保持 Git 历史清晰
  • 降低 code review 难度
  • 避免 unrelated changes 混合

自动拆分规则

Agent 必须基于以下维度拆分 commit。


1. 功能维度拆分

以下情况必须拆分:

feat + fix
feat + refactor
feat + docs

2. 模块维度拆分

不同模块通常应独立 commit:

例如:

logger
socket
cmake
tests
docs

3. 工程维度拆分

以下修改通常必须独立:

  • build system
  • CI/CD
  • dependencies
  • formatter
  • scripts

4. 重构与功能分离

禁止:

refactor + feature

混合提交。

应拆分为:

1. refactor commit
2. feature commit

Commit 粒度判断规则


必须拆分的情况

feat + docs

feat + refactor

fix + formatting

build + runtime logic

tests + unrelated feature

多个独立功能


可以合并的情况

feature + 对应 tests

fix + 对应 docs

refactor + 小范围 cleanup


核心分析流程

第一步:识别核心修改文件

基于:

git diff --stat

识别:

  • 核心模块
  • 高风险修改
  • 大规模变更
  • 重构行为

第二步:深入分析关键文件

执行:

git diff <关键文件>

分析:

  • 功能变化
  • 数据流变化
  • 架构变化
  • 接口变化
  • 配置变化

第三步:识别 Commit Type

自动识别:

  • feat
  • fix
  • refactor
  • perf
  • docs
  • style
  • test
  • build
  • ci
  • chore

第四步:判断是否需要拆分

分析:

  • 是否存在 unrelated changes
  • 是否存在多模块修改
  • 是否存在 docs/build/test 混合
  • 是否存在 feature/refactor 混合

Scope 自动识别规则

根据路径自动推断:

路径scope
src/loggerlogger
src/socketsocket
teststest
docsdocs
modelsmodel
cmakecmake
scriptsscripts

Git Add 推荐系统

Agent 不允许自动 git add

但可以:

  • 推荐 git add 顺序
  • 推荐拆分方案
  • 推荐 staged 粒度

推荐输出格式

单 Commit 场景

检测到当前修改适合单次提交。

建议执行:

git add src/logger/*
git add include/logger/*

推荐 commit message:

refactor(logger): 重构异步日志生命周期管理

多 Commit 场景

检测到当前修改包含多个逻辑变更,建议拆分提交。

--------------------------------------------------

Commit 1:日志模块重构

建议先执行:

git add src/logger/*
git add include/logger/*

推荐 commit:

refactor(logger): 重构异步日志线程生命周期

原因:
- 属于纯结构优化
- 不应与 socket 修复混合

--------------------------------------------------

Commit 2:socket Bug 修复

建议随后执行:

git add src/socket/*

推荐 commit:

fix(socket): 修复 ET 模式连接关闭异常

原因:
- 属于独立 Bug 修复
- 应保持 commit 原子性

Commit Message 生成规范


Subject 规范

要求:

  • 50 字以内
  • 使用中文
  • 使用祈使句
  • 简洁明确
  • 准确体现核心修改

正确示例

feat(parser): 支持 SQL AST 嵌套解析
fix(socket): 修复 epoll ET 模式连接泄漏
refactor(logger): 重构异步日志线程模型

Body 规范

必须:

  • 使用列表格式
  • 按重要性排序
  • 描述技术影响
  • 描述业务价值
  • 避免重复 subject

推荐格式

主要变更:
- 新增 xxx
- 修复 xxx
- 重构 xxx

技术细节:
- 优化 xxx
- 调整 xxx
- 改进 xxx

Footer 规范

仅在必要时生成:

BREAKING CHANGE: xxx
Refs: #123
Closes: #456

多版本输出要求

必须输出:


1. 详细版本

适用于:

  • 大型重构
  • 多模块修改
  • 架构调整

要求:

  • 包含技术细节
  • 明确影响范围
  • 描述设计变化

2. 标准版本(默认推荐)

适用于:

  • 大多数日常提交

要求:

  • 平衡信息量与可读性

3. 简洁版本

适用于:

  • 小型修复
  • 单文件修改

要求:

  • 一句话概括

Git 分析原则

必须遵守

  • 必须重新分析当前 git 状态
  • 必须基于真实 diff
  • 不允许猜测
  • 自动忽略格式噪声
  • 优先关注核心逻辑变化

特殊情况处理


情况一:存在 Breaking Change

例如:

  • API 删除
  • 配置格式变化
  • 数据结构变化

此时必须:

feat!: xxx

或:

BREAKING CHANGE: xxx

情况二:变更目标不明确

例如:

  • 大规模 rename
  • 自动格式化
  • merge 后混合修改

此时:

必须询问用户。

禁止猜测 commit intent。


情况三:提交粒度明显不合理

例如:

  • docs/test/build/core logic 混合
  • 多 feature 混合

此时必须:

  • 建议拆分 commit
  • 输出 Commit Plan
  • 输出 git add 推荐顺序

安全约束


严格禁止

  • 自动执行 git add
  • 自动执行 git commit
  • 自动 push
  • 自动 amend
  • 自动 force push
  • 自动删除文件
  • 修改 git config
  • destructive operations

仅允许

git status
git diff
git log
git show

用户触发词

以下情况必须触发该 Skill:

  • “生成 git commit 信息”
  • “帮我写 commit”
  • “分析 git diff”
  • “生成 conventional commit”
  • “根据修改生成 commit”
  • “拆分 commit”
  • “规划 commit”
  • “commit plan”
  • “/commit”

输出目标

最终输出必须:

  • 清晰
  • 专业
  • 可执行
  • 工程化
  • 易于 code review

帮助用户:

  • 维护整洁 Git 历史
  • 提高提交质量
  • 提高代码审查效率
  • 保持 commit 原子性
  • 建立专业工程化工作流

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.