Commit Skill
Create well-crafted git commit messages following established best practices.
Purpose
Generate commit messages that effectively communicate context about changes to fellow developers and future maintainers. A diff shows what changed; the commit message explains why.
Workflow
1. Analyze Changes
Run these commands to understand the current state:
git status git diff --staged git diff git log --oneline -5
Review:
- •What files are modified, added, or deleted
- •The nature of the changes (bug fix, feature, refactor, docs, etc.)
- •Recent commit message style in the repository
2. Stage Appropriate Files
Critical: Only commit files modified during the current session. Never use git add -A or git add . unless explicitly instructed.
git add <specific-file-paths>
3. Craft the Commit Message
Apply the seven rules from references/git-commit-guide.md:
- •Separate subject from body with a blank line
- •Limit subject to 50 characters (72 hard limit)
- •Capitalize the subject line
- •No period at end of subject
- •Use imperative mood in subject ("Add feature" not "Added feature")
- •Wrap body at 72 characters
- •Explain what and why, not how
Subject Line Test
A proper subject completes this sentence:
If applied, this commit will [your subject line]
Examples:
- •"Add user authentication middleware" ✓
- •"Fix race condition in connection pool" ✓
- •"Added new feature" ✗ (not imperative)
- •"Fixing bug" ✗ (not imperative)
4. Commit Format
For simple changes (no body needed):
git commit -m "Fix typo in README installation section"
For changes requiring explanation:
git commit -m "$(cat <<'EOF' Refactor database connection handling The previous implementation created a new connection for each query, causing performance issues under load. This change introduces connection pooling with a configurable pool size. - Add ConnectionPool class with acquire/release methods - Update DatabaseClient to use pool instead of direct connections - Add pool_size configuration option (default: 10) Resolves: #234 EOF )"
5. Verify
After committing:
git log -1 git status
Quick Reference
| Rule | Good | Bad |
|---|---|---|
| Imperative | "Add tests" | "Added tests" |
| Capitalized | "Fix bug" | "fix bug" |
| No period | "Update docs" | "Update docs." |
| Length | "Add user auth" (13) | "Add user authentication system with JWT tokens and refresh capability" (71) |
Additional Resources
For detailed guidelines and examples, consult:
- •
references/git-commit-guide.md- Complete guide with the seven rules explained in depth, examples of good and bad commits, and references to authoritative sources