Create a git commit with a properly formatted message following best practices.
/commit [message]
When the user invokes this command, follow these steps:
First, run git status to see:
- What files are modified
- What files are staged
- What files are untracked
Run git diff --cached to review staged changes, and git diff for unstaged changes.
Understand the context and purpose of the changes.
If there are unstaged changes that should be included:
- Ask the user which files to stage
- Use
git add <files>to stage them - Or use
git add .if the user wants to stage all changes
Follow the Seven Rules of Great Commit Messages:
- Capitalize the first letter
- Do not end with a period
- Use imperative mood - write as if completing: "If applied, this commit will..."
- Keep it concise and focused
Good examples:
Refactor authentication middleware for clarityAdd password reset functionalityFix memory leak in data processing pipelineUpdate API documentation with new endpoints
Bad examples:
fixed bug.(lowercase, has period)Adding tests(not imperative)Made changes to login(not imperative, vague)
If the change needs more context:
- Leave a blank line after the subject
- Explain what and why, not how
- Provide context about the problem being solved
- Reference related issues or tickets if applicable
Example of a complete message:
Fix race condition in user session handling
Multiple concurrent requests were causing session data to be
overwritten. This was particularly noticeable during rapid
navigation between pages.
The fix implements proper locking mechanisms to ensure session
updates are atomic. This resolves the intermittent logout issues
users were experiencing.
Fixes #234
Create the commit with the properly formatted message:
# For simple commits
git commit -m "Subject line"
# For commits with body (use heredoc or editor)
git commitShow the commit hash and verify the message formatting.
User: /commit
Assistant:
- Check git status and review changes
- Understand the context of changes
- Stage files if needed
- Craft message following the seven rules
- Create commit after confirmation
User: /commit Fix memory leak in image processing
Assistant:
- Verify the message follows best practices
- Check git status
- Stage necessary files if not already staged
- Create commit with provided message
- Consistency is crucial - follow the same style throughout the project
- Commit messages should communicate context about why changes were made
- Good messages help future developers (including yourself) understand the codebase history
- Think of the commit message as documentation for your code changes
Before committing, ensure:
- Subject line uses imperative mood
- Subject line is capitalized
- Subject line has no period at the end
- Subject line is under 50 characters
- Body (if present) wraps at 72 characters
- Body explains why, not how
- No sensitive information included