|
| 1 | +--- |
| 2 | +name: git-commit |
| 3 | +description: '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 grouping' |
| 4 | +license: MIT |
| 5 | +allowed-tools: Bash |
| 6 | +--- |
| 7 | + |
| 8 | +# Git Commit with Conventional Commits |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +Create standardized, semantic git commits using the Conventional Commits specification. Analyze the actual diff to determine appropriate type, scope, and message. |
| 13 | + |
| 14 | +## Conventional Commit Format |
| 15 | + |
| 16 | +``` |
| 17 | +<type>[optional scope]: <description> |
| 18 | +
|
| 19 | +[optional body] |
| 20 | +
|
| 21 | +[optional footer(s)] |
| 22 | +``` |
| 23 | + |
| 24 | +## Commit Types |
| 25 | + |
| 26 | +| Type | Purpose | |
| 27 | +| ---------- | ------------------------------ | |
| 28 | +| `feat` | New feature | |
| 29 | +| `fix` | Bug fix | |
| 30 | +| `docs` | Documentation only | |
| 31 | +| `style` | Formatting/style (no logic) | |
| 32 | +| `refactor` | Code refactor (no feature/fix) | |
| 33 | +| `perf` | Performance improvement | |
| 34 | +| `test` | Add/update tests | |
| 35 | +| `build` | Build system/dependencies | |
| 36 | +| `ci` | CI/config changes | |
| 37 | +| `chore` | Maintenance/misc | |
| 38 | +| `revert` | Revert commit | |
| 39 | + |
| 40 | +## Breaking Changes |
| 41 | + |
| 42 | +``` |
| 43 | +# Exclamation mark after type/scope |
| 44 | +feat!: remove deprecated endpoint |
| 45 | +
|
| 46 | +# BREAKING CHANGE footer |
| 47 | +feat: allow config to extend other configs |
| 48 | +
|
| 49 | +BREAKING CHANGE: `extends` key behavior changed |
| 50 | +``` |
| 51 | + |
| 52 | +## Workflow |
| 53 | + |
| 54 | +### 1. Analyze Diff |
| 55 | + |
| 56 | +```bash |
| 57 | +# If files are staged, use staged diff |
| 58 | +git diff --staged |
| 59 | + |
| 60 | +# If nothing staged, use working tree diff |
| 61 | +git diff |
| 62 | + |
| 63 | +# Also check status |
| 64 | +git status --porcelain |
| 65 | +``` |
| 66 | + |
| 67 | +### 2. Stage Files (if needed) |
| 68 | + |
| 69 | +If nothing is staged or you want to group changes differently: |
| 70 | + |
| 71 | +```bash |
| 72 | +# Stage specific files |
| 73 | +git add path/to/file1 path/to/file2 |
| 74 | + |
| 75 | +# Stage by pattern |
| 76 | +git add *.test.* |
| 77 | +git add src/components/* |
| 78 | + |
| 79 | +# Interactive staging |
| 80 | +git add -p |
| 81 | +``` |
| 82 | + |
| 83 | +**Never commit secrets** (.env, credentials.json, private keys). |
| 84 | + |
| 85 | +### 3. Generate Commit Message |
| 86 | + |
| 87 | +Analyze the diff to determine: |
| 88 | + |
| 89 | +- **Type**: What kind of change is this? |
| 90 | +- **Scope**: What area/module is affected? |
| 91 | +- **Description**: One-line summary of what changed (present tense, imperative mood, <72 chars) |
| 92 | + |
| 93 | +### 4. Execute Commit |
| 94 | + |
| 95 | +```bash |
| 96 | +# Single line |
| 97 | +git commit -m "<type>[scope]: <description>" |
| 98 | + |
| 99 | +# Multi-line with body/footer |
| 100 | +git commit -m "$(cat <<'EOF' |
| 101 | +<type>[scope]: <description> |
| 102 | +
|
| 103 | +<optional body> |
| 104 | +
|
| 105 | +<optional footer> |
| 106 | +EOF |
| 107 | +)" |
| 108 | +``` |
| 109 | + |
| 110 | +## Best Practices |
| 111 | + |
| 112 | +- One logical change per commit |
| 113 | +- Present tense: "add" not "added" |
| 114 | +- Imperative mood: "fix bug" not "fixes bug" |
| 115 | +- Reference issues: `Closes #123`, `Refs #456` |
| 116 | +- Keep description under 72 characters |
| 117 | + |
| 118 | +## Git Safety Protocol |
| 119 | + |
| 120 | +- NEVER update git config |
| 121 | +- NEVER run destructive commands (--force, hard reset) without explicit request |
| 122 | +- NEVER skip hooks (--no-verify) unless user asks |
| 123 | +- NEVER force push to main/master |
| 124 | +- If commit fails due to hooks, fix and create NEW commit (don't amend) |
0 commit comments