Commit Workflow
Generate conventional commit messages following best practices.
Commit Message Format
<type>(<scope>): <subject>
<body>
<footer>
Types
| Type | Description |
|---|---|
feat |
New feature |
fix |
Bug fix |
docs |
Documentation only |
style |
Formatting, no code change |
refactor |
Code restructuring |
perf |
Performance improvement |
test |
Adding/updating tests |
chore |
Build, config, dependencies |
ci |
CI/CD changes |
revert |
Revert previous commit |
Workflow
1. Analyze Changes
git status
git diff --cached
git diff
git log --oneline -5
2. Stage Changes
# Stage specific files
git add <files>
# Or stage all
git add -A
3. Generate Commit Message
Based on the changes:
- Identify the type of change
- Determine the scope (optional)
- Write a concise subject (50 chars max)
- Add body if needed (explain why, not what)
- Reference issues in footer
4. Execute Commit
git commit -m "type(scope): subject"
# Or with body
git commit -m "type(scope): subject" -m "Body paragraph 1" -m "Body paragraph 2"
Examples
# Feature
git commit -m "feat(auth): add OAuth2 login support"
# Bug fix
git commit -m "fix(api): handle null response in user endpoint"
# With body and footer
git commit -m "feat(dashboard): add real-time metrics" -m "Implements WebSocket connection for live data updates. Includes reconnection logic and error handling." -m "Closes #123"
# Breaking change
git commit -m "feat(api)!: change user endpoint response format" -m "BREAKING CHANGE: User endpoint now returns nested object instead of flat structure"
Commit Best Practices
- One logical change per commit - Don't mix unrelated changes
- Write imperative mood - "add feature" not "added feature"
- No period at end of subject line
- Capitalize first letter of subject
- Separate subject from body with blank line
- Wrap body at 72 characters
- Use body to explain why, not what
- Reference issues in footer
Pre-commit Checklist
- All tests pass
- No debug code left
- No sensitive data in changes
- Commit message follows format
- Changes are logically grouped