# Git Commit

> Expert guidance for generating git commits. Use this skill whenever the user asks to commit changes, generate a commit, or says phrases like "genera commit", "make a commit", "commit the changes", or any variation. This skill provides the commit message conventions and decision rules to follow.

- Skill: `spaceyuan/git-commit` (Agent Skill)
- Install (CLI): `npx skillmds@latest add spaceyuan/git-commit`
- Raw SKILL.md: https://api.skillmd.com/api/skills/spaceyuan/git-commit/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: spaceyuan (https://skillmd.com/u/spaceyuan)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/spaceyuan/git-commit

---


# Git Commit Skill

## Conventional Commits - 类型选择规则

根据变更内容选择 `type`，类型名保持英文不变：

| 提交类型 | 含义 |
| --- | --- |
| `init` | 首次创建 |
| `feat` | 新功能、能力增强 |
| `fix` | 修复问题 |
| `refactor` | 仅重构代码，不改变行为 |
| `chore` | 配置、依赖、Docker、CI/CD、脚本、工具类变更 |
| `docs` | README、注释、文档块、API 文档 |
| `style` | 空格、格式、缩进等，不改变逻辑 |
| `test` | 新增、更新或修复测试 |
| `perf` | 查询优化、缓存、算法优化 |
| `build` | 构建系统或依赖变更 |
| `workflow` | 工作流定义 |
| `release` | 发布版本 |
| `revert` | 回滚提交 |
| `merge` | 合并分支 |

## Scope 规则

从变更路径中选择**最贴近且最有意义的模块名**作为 scope：

- `app/Http/Controllers/InvoiceController.php` -> scope: `invoices`
- `app/Services/AuthService.php` -> scope: `auth`
- `database/migrations/` -> scope: `migrations`
- `docker-compose.yml` / `Dockerfile` -> scope: `docker`
- `angular/src/app/modules/orders/` -> scope: `orders`
- 涉及多个不相关模块 -> 省略 scope

## 提交信息规则

- 采用 `type(scope): 中文摘要` 或 `type: 中文摘要`
- `type` 和 `scope` 保持英文规范不变，正文内容使用中文
- 摘要和 body 优先使用中文，必要时可保留英文术语、模块名、缩写
- 摘要要简洁、明确、面向结果
- 末尾不要加句号
- 长度尽量控制在 72 个字符以内；中文场景下以简洁为先

## Body 规则（可选）

当有**3 个或更多有意义的变更**时，再补充 body。使用中文条目，必要时保留英文术语：

```
feat(invoices): 支持 PDF 导出

- 新增 InvoiceService，用于生成 PDF
- 更新 InvoiceController，接入导出接口
- 在发票详情页增加导出按钮
```

## 边界情况

- **没有暂存内容** -> 先执行 `git add -A` 再提交
- **只有部分内容已暂存** -> 只提交已暂存内容，并提示仍有未暂存文件
- **没有任何变更** -> 直接告知用户，不执行提交
- **存在合并冲突** -> 提示并中止
- **处于 detached HEAD** -> 先提示再继续
- **只有二进制文件** -> 使用 `chore`，并在 body 中列出文件
- **超过 20 个文件** -> 在 body 中按目录分组说明

## 确认输出格式（中文）

```
✅ 已在分支: <branch>

📁 已提交文件:
  - path/to/file.php
  - path/to/another.ts

📝 提交信息:
  <full commit message>

🔖 Commit: <short hash>
```

默认不执行 push。只有用户明确要求时，才补充远端推送结果。

