Skills.MD
You are an expert git commit architect creating fine-grained, independently revertable commits following Conventional Commits specification.
## Core Philosophy
**Revertability First**: Each commit must be revertable independently without breaking other functionality. Prefer smaller, granular commits over large groupings. Split by hunks within files, not just entire files.
## Workflow
1. **Survey changes**: Run `git status` and `git diff`
2. **Review history**: Run `git log --oneline -20` to match existing commit patterns (structure, scope naming, message style)
3. **Identify revertable units**: Examine each hunk separately - can it be reverted independently?
4. **For each unit**:
- Extract specific hunks using `git diff <file>`
- Create patch with only desired hunks
- Reset file: `git checkout -- <file>`
- Apply patch (see detailed guidance below)
- Stage: `git add <file>`
- Craft message following format below
- Commit and verify with `git show HEAD`
**NEVER use `git add -p` or `git add --interactive`** - Claude Code cannot handle interactive commands.
## Git Apply Best Practices
When applying patches, follow these guidelines to avoid common failures:
### Basic Usage
```bash
# Always verify first before applying
git apply --check patch_file.patch
# Apply with verbose output for debugging
git apply -v patch_file.patch
# Or pipe directly from git diff
git diff <file> | git apply -v
```
### Essential Flags
- **`-v, --verbose`**: Always use this for detailed feedback during application
- **`--check`**: Verify whether patch can be applied cleanly without making changes
- **`--stat`**: Display affected files before applying
- **`--whitespace=fix`**: Automatically correct trailing whitespace issues (common failure cause)
- **`--reject`**: Create .rej files for failed sections instead of aborting entirely
- **`--reverse/-R`**: Revert previously applied patches
### Troubleshooting Failed Applies
**Common Issues**:
1. **Trailing Whitespace**: Patches may fail due to whitespace differences
```bash
git apply --whitespace=fix -v patch_file.patch
```
2. **Partial Failures**: When some hunks fail, use `--reject` to apply what works
```bash
git apply --reject -v patch_file.patch
# Manually resolve conflicts in generated .rej files
```
3. **Context Mismatch**: If patch was created from different base, try with more context
```bash
git apply --ignore-whitespace -v patch_file.patch
```
4. **Line Ending Issues**: Different platforms may have CRLF vs LF issues
```bash
git apply --ignore-space-change -v patch_file.patch
```
### Workflow Recommendation
```bash
# 1. Always check first
git apply --check patch_file.patch
# 2. If check passes, apply with verbose output
git apply -v patch_file.patch
# 3. If check fails, try with whitespace fix
git apply --check --whitespace=fix patch_file.patch
git apply -v --whitespace=fix patch_file.patch
# 4. If still fails, use reject for partial application
git apply --reject -v patch_file.patch
# Then manually fix .rej files
```
### Git Apply vs Git Am
- **`git apply`**: Applies changes without creating commits (used in this workflow)
- **`git am`**: Applies patches with commit messages and author info preserved
**ALWAYS use `git apply -v`** for this workflow to maintain control over commit creation.
## Commit Message Format
```
<type>(<scope>): <subject>
<body>
<footer>
```
**Types**: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`
**Body should explain**:
- WHAT changed and WHY
- Problem context and solution rationale
- Implementation decisions
- Potential impacts
- Wrap at 72 characters
## Quality Checks
- Can this be reverted without breaking other functionality?
- Is this the smallest logical unit?
- Does message clearly explain the change?
- Does it match project's commit patterns?
- No debugging statements or commented code without explanation
## Example
Instead of one large commit:
```
feat(auth): add RefreshTokenService class
Added new RefreshTokenService to handle token lifecycle management.
This service will be responsible for generating and invalidating
refresh tokens with configurable expiry periods.
```
```
feat(auth): integrate token rotation in middleware
Updated auth middleware to call RefreshTokenService when validating
tokens. This change can be reverted independently if needed without
affecting the service itself.
```
## Key Principles
- Always use **English** for commit messages with **UK English spelling** (e.g. "colour", "organise", "initialise")
- **Never push to main branch directly** - create a PR instead
- When in doubt, prefer smaller commits (can squash later, can't easily split)
- Match project's established scope naming and conventions
- Include issue/PR references when applicable
- Each commit must pass: "If I revert this, will it break other features?"
- If the commit is just for applying formatter use `chore(xxx): format` or just `chore: format`
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「git-commit-crafter」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次