davila7--claude-code-templates
1 行
4.7 KiB
JSON
1 行
4.7 KiB
JSON
{"content": "---\nname: Git Commit Helper\ndescription: Generate descriptive commit messages by analyzing git diffs. Use when the user asks for help writing commit messages or reviewing staged changes.\nhooks:\n PostToolUse:\n - matcher: \"Bash\"\n hooks:\n - type: command\n command: \"echo \\\"[$(date)] Git Commit Helper: Analyzed git diff for commit message\\\" >> ~/.claude/git-commit-helper.log\"\n---\n\n# Git Commit Helper\n\n## Quick start\n\nAnalyze staged changes and generate commit message:\n\n```bash\n# View staged changes\ngit diff --staged\n\n# Generate commit message based on changes\n# (Claude will analyze the diff and suggest a message)\n```\n\n## Commit message format\n\nFollow conventional commits format:\n\n```\n<type>(<scope>): <description>\n\n[optional body]\n\n[optional footer]\n```\n\n### Types\n\n- **feat**: New feature\n- **fix**: Bug fix\n- **docs**: Documentation changes\n- **style**: Code style changes (formatting, missing semicolons)\n- **refactor**: Code refactoring\n- **test**: Adding or updating tests\n- **chore**: Maintenance tasks\n\n### Examples\n\n**Feature commit:**\n```\nfeat(auth): add JWT authentication\n\nImplement JWT-based authentication system with:\n- Login endpoint with token generation\n- Token validation middleware\n- Refresh token support\n```\n\n**Bug fix:**\n```\nfix(api): handle null values in user profile\n\nPrevent crashes when user profile fields are null.\nAdd null checks before accessing nested properties.\n```\n\n**Refactor:**\n```\nrefactor(database): simplify query builder\n\nExtract common query patterns into reusable functions.\nReduce code duplication in database layer.\n```\n\n## Analyzing changes\n\nReview what's being committed:\n\n```bash\n# Show files changed\ngit status\n\n# Show detailed changes\ngit diff --staged\n\n# Show statistics\ngit diff --staged --stat\n\n# Show changes for specific file\ngit diff --staged path/to/file\n```\n\n## Commit message guidelines\n\n**DO:**\n- Use imperative mood (\"add feature\" not \"added feature\")\n- Keep first line under 50 characters\n- Capitalize first letter\n- No period at end of summary\n- Explain WHY not just WHAT in body\n\n**DON'T:**\n- Use vague messages like \"update\" or \"fix stuff\"\n- Include technical implementation details in summary\n- Write paragraphs in summary line\n- Use past tense\n\n## Multi-file commits\n\nWhen committing multiple related changes:\n\n```\nrefactor(core): restructure authentication module\n\n- Move auth logic from controllers to service layer\n- Extract validation into separate validators\n- Update tests to use new structure\n- Add integration tests for auth flow\n\nBreaking change: Auth service now requires config object\n```\n\n## Scope examples\n\n**Frontend:**\n- `feat(ui): add loading spinner to dashboard`\n- `fix(form): validate email format`\n\n**Backend:**\n- `feat(api): add user profile endpoint`\n- `fix(db): resolve connection pool leak`\n\n**Infrastructure:**\n- `chore(ci): update Node version to 20`\n- `feat(docker): add multi-stage build`\n\n## Breaking changes\n\nIndicate breaking changes clearly:\n\n```\nfeat(api)!: restructure API response format\n\nBREAKING CHANGE: All API responses now follow JSON:API spec\n\nPrevious format:\n{ \"data\": {...}, \"status\": \"ok\" }\n\nNew format:\n{ \"data\": {...}, \"meta\": {...} }\n\nMigration guide: Update client code to handle new response structure\n```\n\n## Template workflow\n\n1. **Review changes**: `git diff --staged`\n2. **Identify type**: Is it feat, fix, refactor, etc.?\n3. **Determine scope**: What part of the codebase?\n4. **Write summary**: Brief, imperative description\n5. **Add body**: Explain why and what impact\n6. **Note breaking changes**: If applicable\n\n## Interactive commit helper\n\nUse `git add -p` for selective staging:\n\n```bash\n# Stage changes interactively\ngit add -p\n\n# Review what's staged\ngit diff --staged\n\n# Commit with message\ngit commit -m \"type(scope): description\"\n```\n\n## Amending commits\n\nFix the last commit message:\n\n```bash\n# Amend commit message only\ngit commit --amend\n\n# Amend and add more changes\ngit add forgotten-file.js\ngit commit --amend --no-edit\n```\n\n## Best practices\n\n1. **Atomic commits** - One logical change per commit\n2. **Test before commit** - Ensure code works\n3. **Reference issues** - Include issue numbers if applicable\n4. **Keep it focused** - Don't mix unrelated changes\n5. **Write for humans** - Future you will read this\n\n## Commit message checklist\n\n- [ ] Type is appropriate (feat/fix/docs/etc.)\n- [ ] Scope is specific and clear\n- [ ] Summary is under 50 characters\n- [ ] Summary uses imperative mood\n- [ ] Body explains WHY not just WHAT\n- [ ] Breaking changes are clearly marked\n- [ ] Related issue numbers are included\n"} |