# Git Commit

> 使用约定式提交规范执行 git commit

- **Type:** Skill
- **Install:** `agentstack add skill-nicholyx-ai-skills-git-commit`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [nicholyx](https://agentstack.voostack.com/s/nicholyx)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [nicholyx](https://github.com/nicholyx)
- **Source:** https://github.com/nicholyx/ai-skills/tree/main/custom/daily/git-commit

## Install

```sh
agentstack add skill-nicholyx-ai-skills-git-commit
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Git 约定式提交

## 概述

使用约定式提交（Conventional Commits）规范创建标准化、语义化的 git commit。分析实际 diff 来确定合适的 type、scope 和消息。

## 语言设置

**默认生成中文提交消息。** 用户可通过参数指定其他语言，例如：

- 无参数 → 中文消息
- `--lang=en` → 英文消息

## 约定式提交格式

```
[可选 scope]: 

[可选正文]

[可选脚注]
```

### 中文消息示例

```
feat(auth): 引入 JWT 验证以保护接口安全

实现 JWT Token 验证中间件，解决接口未鉴权的安全风险：
- 验证 Token 签名和过期时间，防止伪造请求
- 从 Payload 提取用户声明，供下游使用
- 将用户上下文注入请求对象，避免重复查询
- 处理 Refresh Token 轮换，保持会话连续性
```

### 英文消息示例

```
feat(auth): add JWT validation to secure API endpoints
```

## 提交类型

| 类型       | 用途                         |
| ---------- | ---------------------------- |
| `feat`     | 新功能                       |
| `fix`      | 修复缺陷                     |
| `docs`     | 仅文档变更                   |
| `style`    | 代码格式/风格（不影响逻辑）  |
| `refactor` | 重构（非功能/非修复）        |
| `perf`     | 性能优化                     |
| `test`     | 新增/更新测试                |
| `build`    | 构建系统/依赖变更            |
| `ci`       | CI/配置变更                  |
| `chore`    | 维护/杂项                    |
| `revert`   | 回退提交                     |

## 破坏性变更

```
# type/scope 后加感叹号
feat!: 移除已废弃的接口以简化 API 维护

# BREAKING CHANGE 脚注
feat: 支持配置继承以减少重复配置

BREAKING CHANGE: `extends` 键的行为已变更
```

## 提交拆分策略

当检测到以下情况时，应建议拆分为多个提交：

1. **混合类型**：新功能 + 缺陷修复在同一提交中
2. **多关注点**：不相关的变更混在一起
3. **大范围变更**：跨越多个模块的修改
4. **文件模式混合**：源码 + 测试 + 文档混杂
5. **依赖混杂**：依赖更新与功能代码混合

## 工作流程

### 1. 分析差异

```bash
# 首先检查暂存区
git diff --staged

# 同时检查状态，判断暂存区和工作区情况
git status --porcelain
```

**默认只提交暂存区（staged）的代码。** 流程如下：

1. 先检查暂存区是否有内容（`git diff --staged` 是否有输出）
2. **暂存区有内容** → 直接使用暂存区差异生成提交消息
3. **暂存区无内容** → 提示用户："暂存区没有文件，是否要提交工作区的变更？" — 等待用户确认后再执行

### 2. 暂存文件（如需要）

仅在用户确认提交工作区变更后，或需要按逻辑分组时暂存：

```bash
# 暂存指定文件
git add path/to/file1 path/to/file2

# 按模式暂存
git add *.test.*
git add src/components/*
```

**绝不能提交密钥文件**（.env、credentials.json、私钥等）。

### 3. 生成提交消息

分析 diff 来确定：

- **Type**：这是什么类型的变更？
- **Scope**：影响哪个区域/模块？
- **描述**：一行概括**为什么要做这个变更**（现在时态、祈使语气、[scope]: "

# 多行，含正文/脚注
git commit -m "$(cat [scope]: 

EOF
)"
```

### 5. Push 规则

**默认不执行 `git push`。** 只有当用户明确说了"push"或"推送"时，才在提交后执行 push。

## 最佳实践

- 一个提交只包含一个逻辑变更
- 使用现在时态："添加" 而非 "添加了"
- 使用祈使语气："修复缺陷" 而非 "修复了缺陷"
- 引用议题：`Closes #123`、`Refs #456`
- 描述保持在 72 字符以内

## Git 安全协议

- 禁止修改 git config
- 未经用户明确要求，禁止执行破坏性命令（--force、hard reset）
- 未经用户要求，禁止跳过钩子（--no-verify）
- 禁止 force push 到 main/master
- 如果提交因钩子失败，修复问题后创建新提交（不要 amend）

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [nicholyx](https://github.com/nicholyx)
- **Source:** [nicholyx/ai-skills](https://github.com/nicholyx/ai-skills)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** yes
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-nicholyx-ai-skills-git-commit
- Seller: https://agentstack.voostack.com/s/nicholyx
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
