1---2name: git-commit-23description: Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping4license: MIT5---67# Git commit with Conventional Commits89Create one logical Git commit by inspecting `git status --porcelain`, choosing the correct staged or working-tree diff, staging only intended files, and writing a Conventional Commits message that matches the actual change.1011## When to invoke1213- "Commit these changes."14- "Create a git commit for my staged files."15- "Use /commit for this diff."16- "Generate a conventional commit message and commit it."17- "Stage this logical change and commit it."1819## Commit workflow20211. Run `git status --porcelain` before touching the index.222. If files are already staged, inspect `git diff --staged`; otherwise inspect `git diff` for the working tree the user wants included.233. Decide whether the requested change is one logical commit. If unrelated changes are present, stage specific paths only: `git add path/to/file1 path/to/file2`.244. For mixed hunks in the same file, use `git add -p` instead of staging the whole file.255. Preserve a user-supplied type, scope, description, issue reference, or breaking-change note unless the inspected diff contradicts it; explain any necessary correction.266. Generate the subject from the diff: type, optional scope, and imperative description under 72 characters.277. Execute `git commit -m "<type>[scope]: <description>"` when the user asked to commit. For a body or footer, pass separate `-m` arguments rather than embedding command substitutions.288. If hooks fail, fix the hook findings and create a new commit attempt. Do not amend unless the user explicitly asks.2930## Conventional Commit format3132```text33<type>[optional scope]: <description>3435[optional body]3637[optional footer(s)]38```3940| Element | Rule | Example |41| --- | --- | --- |42| `type` | Choose the primary intent of the diff. | `feat`, `fix`, `docs` |43| `scope` | Add a short module, package, app, or feature area only when it clarifies ownership. | `api`, `auth`, `docs` |44| `description` | Present tense, imperative mood, no trailing period, preferably <72 chars. | `add token refresh guard` |45| `body` | Explain why, migration notes, or context that does not fit the subject. | `This keeps old clients working during rollout.` |46| `footer` | Use for issue references and breaking changes. | `Closes #123`, `Refs #456`, `BREAKING CHANGE: extends key behavior changed` |4748## Commit types4950| Type | Use when the diff primarily changes |51| --- | --- |52| `feat` | User-visible capability or supported behavior. |53| `fix` | Bug fix, regression, broken behavior, or incorrect output. |54| `docs` | Documentation only. |55| `style` | Formatting/style only, with no logic change. |56| `refactor` | Internal restructuring with no feature or fix. |57| `perf` | Performance improvement. |58| `test` | Test additions or corrections. |59| `build` | Build system, packaging, dependency, or generated artifact behavior. |60| `ci` | CI, workflow, release automation, or config changes. |61| `chore` | Maintenance/misc work that does not fit another type. |62| `revert` | Reverts an earlier commit. |6364## Staging rules6566| Situation | Command | Constraint |67| --- | --- | --- |68| Exact files requested | `git add path/to/file1 path/to/file2` | Stage only named files. |69| Test files by pattern | `git add *.test.*` | Confirm the pattern does not catch unrelated files. |70| Component directory | `git add src/components/*` | Use only when all files belong to the same logical change. |71| Partial file | `git add -p` | Prefer hunk staging to unrelated whole-file commits. |72| Already staged | `git diff --staged` | Do not replace the index unless the user asks. |7374## Git safety protocol7576- Never commit secrets: `.env`, `credentials.json`, private keys, tokens, or generated secret dumps.77- Never update git config as part of committing.78- Never run destructive commands such as `--force` pushes or hard resets without an explicit request.79- Never skip hooks with `--no-verify` unless the user explicitly asks.80- Never force push to `main` or `master`.81- Reference issues with `Closes #123` only when the diff actually completes the issue; use `Refs #456` for partial work.82- Preserve legacy decision labels when useful: `type/scope`, `body/footer`, `area/module`, `feature/fix`, `system/dependencies`, `CI/config`, and `Add/update` tests all map to the Conventional Commits choices above.83- NEVER force push to `main/master`; keep this uppercase warning visible because it is the core Git safety rule.8485## Breaking changes8687Use either an exclamation mark in the subject or a `BREAKING CHANGE:` footer; use both when the risk is high or external users must notice it.8889```text90feat!: remove deprecated endpoint9192feat: allow config to extend other configs9394BREAKING CHANGE: `extends` key behavior changed95```9697## Gotchas9899- **Do not stage by habit**: `git add .` can silently include secrets or another user's work.100- **Do not use past tense**: write `fix auth redirect`, not `fixed auth redirect`.101- **Do not force a vague scope**: omit the scope rather than writing `chore(repo)` when the type already carries the meaning.102- **Do not amend after hook failure by default**: the original instruction requires a new commit attempt unless the user asks for amend.103104## Output template105106```markdown107## Git commit result108109**Status:** committed | message only | blocked110**Files reviewed:** <staged count> staged, <unstaged count> unstaged, <untracked count> untracked111**Diff used:** `git diff --staged` | `git diff`112113**Commit message**114Subject: `<type>[optional scope]: <description>`115Body: `<body or none>`116Footer: `<footer(s) or none>`117118**Commands run**119- `git status --porcelain`120- `git diff --staged` or `git diff`121- `git add <paths>` / `git add -p` if staging was needed122- `git commit -m "<subject>" [-m "<body>"] [-m "<footer>"]`123124**Safety checks**125- Secrets check: pass | blocked with evidence126- Hook result: pass | fail with evidence127```128129## Quality gate130131- [ ] `git status --porcelain` was reviewed before staging or committing.132- [ ] The diff inspected is the diff being committed: `git diff --staged` for staged files or `git diff` for intended unstaged files.133- [ ] The commit contains one logical change and no unintended files.134- [ ] No secrets such as `.env`, `credentials.json`, private keys, or tokens are staged.135- [ ] The type is one of `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, or `revert`.136- [ ] The description is imperative, present tense, non-empty, and under 72 characters where practical.137- [ ] Breaking changes use `!` or a `BREAKING CHANGE:` footer.138- [ ] Hooks were not skipped unless the user explicitly requested `--no-verify`.