home / skills / dcjanus / prompts / git-commit

git-commit skill

/skills/git-commit

This skill guides git commits, branch naming, and messaging according to Conventional Commits, enhancing accuracy, consistency, and collaboration.

npx playbooks add skill dcjanus/prompts --skill git-commit

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.4 KB
---
name: git-commit
description: 处理 git 提交/推送/分支命名与提交信息规范;当用户要求 commit、push、起分支或整理 commit message 时使用。
---

用于处理 git 提交相关操作与约定,重点是授权边界、提交信息、分支命名和常用非交互命令。

## Quick start

```bash
cd /path/to/repo
git status --short
git add <paths>
git commit -m "feat(scope): short summary"
```

## 使用约定

- 未收到用户当次明确 `commit` 指令时,不执行 `git commit`。
- 未收到用户当次明确 `push` 指令时,不执行 `git push`。
- 可以在确有需要时询问是否需要 `commit`;不得主动询问是否需要 `push`。
- 如存在授权歧义,先向用户确认,再执行相关 git 写操作。
- 提交信息使用简洁、精确、描述性强的英文,遵循 [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/);可行时尽量包含 scope。
- 创建分支时尽量遵循 [Conventional Branch](https://conventional-branch.github.io/)。
- 提交时追加 `Co-authored-by: OpenAI Codex <[email protected]>` trailer。
- 日常切换/恢复操作优先使用 `git switch` 与 `git restore`,尽量避免 `git checkout`。
- 进行提交前,先确认工作区中哪些改动属于当前任务,避免把无关改动混入同一个提交。

## 常用场景

- 创建提交:

```bash
git status --short
git add <paths>
git commit -m "fix(scope): concise summary"
```

- 创建带 trailer 的提交:

```bash
git commit -m "feat(scope): concise summary" -m "Co-authored-by: OpenAI Codex <[email protected]>"
```

- 补充说明较多的提交:

```bash
git commit -m "refactor(scope): concise summary" -m "Explain the key intent or constraint." -m "Co-authored-by: OpenAI Codex <[email protected]>"
```

- 新建并切换分支:

```bash
git switch -c feat/scope-short-summary
```

- 切换已有分支:

```bash
git switch <branch>
```

- 丢弃工作区单文件改动:

```bash
git restore <path>
```

- 取消暂存:

```bash
git restore --staged <path>
```

## 提交信息约定

- 推荐格式:`type(scope): short summary`
- 常见 `type`:`feat`、`fix`、`refactor`、`docs`、`test`、`chore`
- `summary` 保持简短,聚焦结果,不写空泛描述
- 若无合适 scope,可省略 scope,但优先保留

## 冷门参数怎么查

- `git commit --help`
- `git switch --help`
- `git restore --help`
- `git push --help`

## 资源

- [SKILL.md](SKILL.md)

Overview

This skill helps you prepare and manage git commits, pushes, branch names, and commit-message conventions. It enforces clear authorization boundaries so no write actions (commit/push) are performed without explicit user instruction. It favors Conventional Commits and Conventional Branch naming and appends a required Co-authored-by trailer when creating commits. It also prefers git switch/restore for non-destructive workspace operations.

How this skill works

When asked to create or format a commit, the skill inspects the working tree status and suggests precise, English commit messages following Conventional Commits (type(scope): short summary). It can generate branch names that match Conventional Branch patterns and produce the exact git commands to run. It will not run git commit or git push unless the user explicitly asks; for ambiguous authorization it asks for confirmation before any write operation.

When to use it

  • You need a concise, Conventional-Commits compliant commit message.
  • You want a recommended branch name for a new feature or fix.
  • You need command-line snippets to stage, commit (with trailers), or push changes.
  • You want to avoid mixing unrelated changes into one commit.
  • You need help restoring or switching files/branches safely using git restore/switch.

Best practices

  • Always confirm which changed files belong to the current task before staging.
  • Write commit summaries in English, short and result-focused: type(scope): summary.
  • Include scope when practical; omit only if none applies.
  • Append: Co-authored-by: OpenAI Codex <[email protected]> as a trailer on commits.
  • Prefer git switch and git restore over git checkout for switching/restoring.

Example use cases

  • Generate a commit message for a bug fix: suggests 'fix(network): handle timeout on reconnect'.
  • Create a branch name for a new feature: recommends 'feat/auth-refresh-token'.
  • Produce the exact commands to stage files and commit with multiple message paragraphs and trailer.
  • Show how to discard a single file change with git restore or unstage with git restore --staged.
  • Outline the safe sequence to switch branches and push after explicit user approval.

FAQ

Will you ever run git commit or git push on my behalf?

No. The skill will not execute commit or push unless you explicitly instruct it to do so. If there is authorization ambiguity it asks first.

What commit message format do you recommend?

Use Conventional Commits: type(scope): short summary. Use types like feat, fix, refactor, docs, test, chore, and keep summaries concise and descriptive.

Should I always include the Co-authored-by trailer?

Yes—this skill appends 'Co-authored-by: OpenAI Codex <[email protected]>' to commits as a required trailer.