---
description: Create well-structured commits with descriptive messages
argument-hint: [optional commit type]
---

# /eg:commit

You are tasked with creating well-structured commits with descriptive messages that follow the project's commit standards and conventional format.

Input: `$ARGUMENTS`

## Step 1: Parse Commit Type

If an argument is provided, it's the commit type:
- feat, fix, docs, style, refactor, test, chore, perf, build, ci, revert

If not provided, infer from staged changes.

## Step 2: Analyze Staged Changes

Check what's staged:

```
!git status --porcelain | grep "^[AM]"
!git diff --cached --stat
!git diff --cached | head -500
```

If nothing is staged:
```
!echo "No staged changes. Stage files with 'git add' first."
```

## Step 3: Determine Commit Type

If type not provided, infer from changes:

```
# Check file types and changes
!git diff --cached --name-only | while read file; do
  echo "- $file"
done
```

Type mapping:
- New features/functionality → `feat`
- Bug fixes → `fix`
- Documentation only → `docs`
- Code style/formatting → `style`
- Code refactoring → `refactor`
- Test additions/fixes → `test`
- Build/tooling changes → `chore`
- Performance improvements → `perf`

## Step 4: Generate Commit Message

Use the Task tool to create the message:

```
Task(
  description="Generate commit message",
  prompt=`
    Create a conventional commit message for the staged changes.
    
    Commit type: {commit-type}
    
    Analyze the changes and create a message following this format:
    <type>(<scope>): <subject>
    
    <body>
    
    <footer>
    
    Guidelines:
    - Subject: Imperative mood, 50 chars or less ("Add feature" not "Added feature")
    - Body: Explain what and why, not how
    - Include context for future maintainers
    - Reference issues if applicable (Fixes #123, Relates to #456)
    - Note breaking changes with "BREAKING CHANGE:" prefix
    
    Focus on clarity and usefulness for future developers.
  `,
  subagent_type="summarizer"
)
```

## Step 5: Create Commit

Execute the commit:

```
!git commit -m "{generated-subject}" -m "{generated-body}"
```

Or for complex commits with footer:
```
!git commit -F- <<EOF
{generated-subject}

{generated-body}

{generated-footer}
EOF
```

## Step 6: Confirm Success

Verify commit was created:

```
!git log -1 --oneline
```

## Conventional Commit Examples

- `feat(auth): add OAuth2 login support`
- `fix(api): handle null response in user endpoint`
- `docs(readme): update installation instructions`
- `refactor(core): extract validation logic to utils`
- `test(user): add integration tests for profile update`
- `perf(db): optimize user query with index`
- `chore(deps): update dependencies to latest versions`

The commit message should clearly communicate the intent and impact of the changes.