---
name: gitmoji
description: Generate a single-line Gitmoji commit subject from staged changes and the current branch name. Use when the user asks to write a gitmoji commit message, generate a gitmoji subject, 生成 gitmoji 提交信息, 写 gitmoji 风格提交说明, or wants a commit message with an emoji prefix instead of a typed commit prefix such as Conventional Commits or Semantic Commits.
commit-message-protocol: gitmoji
---

# Gitmoji Commit Message

## Purpose

Generate a single-line Gitmoji commit subject from the current staged changes.

Requirements:
- Follow the configured commit message language for the summary.
- Start the subject with one Gitmoji emoji that best matches the staged change intent.
- Extract a Jira ID or work item ID from the current branch name when possible and place it after the emoji.
- Ignore branch tokens that are clearly version numbers, release numbers, dates, or pure numeric identifiers.
- Do not output a typed commit prefix such as `feat:` or `fix:`.

## Workflow

1. Confirm there are staged changes before drafting the message.
2. Read the staged diff, not the full working tree, and summarize only what is staged.
3. Read the current branch name.
4. Extract a ticket-like identifier from the branch name.
5. Choose the Gitmoji that best matches the staged change intent.
6. Generate a concise subject line.

## Commands

Use git commands that inspect only the staged area:

```bash
git branch --show-current
git diff --cached --name-only
git diff --cached --stat
git diff --cached
```

If there are no staged changes, do not invent a message. Tell the user there is nothing staged to commit.

## Ticket Extraction

Extract a meaningful ticket-like token from the branch name.

Preferred pattern:

```text
[A-Za-z][A-Za-z0-9]+-\d+
```

Rules:
- If the branch contains **multiple** substrings that match this pattern, use the **last** match. Prefix segments are often release or iteration noise; the real work item ID is usually at the end (for example `...-CZGZH-SCP-7921` → `SCP-7921`).
- Keep the extracted ticket exactly as it appears in the branch name.
- The pattern requires a **leading letter** in the key, so a numeric prefix such as `202-` before the key is not treated as the project key (for example `feature/202-SCP-7921` → `SCP-7921`).
- Ignore tokens that look like versions or releases when interpreting the branch, for example `1.2.3`, `v2.0.1`, `2026.03`, `release-1.0.0`.
- Ignore pure numbers such as `1234`.
- **Do not** substitute unrelated acronyms from the diff or summary (for example `SCA`) for the branch ticket. If the branch yields a `Key-123` token, the subject must include that exact ticket form after the Gitmoji.
- If no valid ticket is found, omit it.

## Gitmoji Selection

Choose the narrowest Gitmoji that matches the staged change intent:

- `✨` new feature or user-visible capability
- `🐛` bug fix or behavior correction
- `♻️` refactoring without behavior change
- `📝` documentation only
- `✅` tests only
- `🚀` performance improvement
- `🔧` tooling, configuration, or maintenance changes
- `🔥` removing obsolete code or files
- `🚑️` urgent production fix
- `💄` UI or style-only adjustments

Do not default to `✨`. Match the actual staged diff.

## Output Format

Always output a single-line subject only.

Subject template with ticket:

```text
<gitmoji> <ticket-id> <summary>
```

Subject template without ticket:

```text
<gitmoji> <summary>
```

Subject rules:
- Keep it concise and specific.
- Follow the configured commit message language.
- Focus on the purpose of the staged change, not a file list.
- Do not end the subject with punctuation.
- Do not add extra labels, explanations, or markdown.

## Examples

Branch: `feature/ABC-5690-user-center-sync`
Staged intent: user center integration

Output:

```text
✨ ABC-5690 用户中心模块数据联调
```

Branch: `fix/abc-6021-order-status`
Staged intent: fix incorrect status mapping

Output:

```text
🐛 abc-6021 修复订单状态映射错误
```

Branch: `chore/update-readme`
Staged intent: update README

Output:

```text
📝 更新项目接入说明
```

Branch: `feature/202SP5-CZGZH-SCP-7921`
Staged intent: add SCA security component types

Output:

```text
✨ SCP-7921 新增 SCA 安全组件类型支持
```

Branch: `feature/202-SCP-7921`
Staged intent: same as above

Output:

```text
✨ SCP-7921 新增 SCA 安全组件类型支持
```

## Response Style

When returning the result to the user:
- Return exactly one final commit message subject line only.
- If the staged diff is ambiguous, choose the single best subject and return only that one line.
- Do not add explanations, labels, bullets, or alternative candidates.

## Additional Resources

- For more examples, see [references/examples.md](references/examples.md)
