🤖
Cursor AIでコミットメッセージを劇的に改善する方法
Cursor AIでコミットメッセージを劇的に改善する方法
概要
Cursor AIの動作をカスタマイズする.cursorrules
ファイルを整備したところ、自動生成されるコミットメッセージが大幅に改善されました。冗長な長文から、プレフィックス付きの簡潔で明確なメッセージへと変化し、開発効率が向上しています。
変更前の問題点
Cursor AIでコミットメッセージを自動生成させると:
- 冗長で長い説明文になりがち
- プレフィックスがなく、変更の種類が一目でわからない
- 日本語と英語が混在して統一感がない
- 50文字を大幅に超える長文になることも
例:
Updated the journal editor component to include new tag selection functionality and improved the overall user experience
解決策:.cursorrulesでルールを明確化
以下のようなルールをGit Commit Messagesセクションに定義:
## Git Commit Messages
When generating git commit messages:
- **ALWAYS use a prefix** (feat, fix, docs, style, refactor, perf, test, chore)
- Keep the main message under 50 characters INCLUDING the prefix
- Use imperative mood after the prefix
- Be specific but concise
- No periods at the end
- Format: `prefix: message`
- **Language**: Always use English for commit messages
### Prefix Rules (Angular Convention):
- `feat:` A new feature
- `fix:` A bug fix
- `docs:` Documentation only changes
- `style:` Changes that do not affect the meaning of the code (formatting, missing semi-colons, etc)
- `refactor:` A code change that neither fixes a bug nor adds a feature
- `perf:` A code change that improves performance
- `test:` Adding missing or correcting existing tests
- `chore:` Changes to the build process or auxiliary tools and libraries
### Code Comments Language:
- **For international projects**: Use English comments
- **For domestic Japanese projects**: Use Japanese comments (コメントを日本語で記述した場合)
- Choose based on your team's preference and project requirements
変更後の効果
ルール適用後のコミットメッセージ:
feat: add tag selector component
fix: resolve OAuth redirect issue
refactor: simplify journal editor layout
style: format hashtag functions
改善ポイント
- 一貫性: すべてのコミットが同じフォーマットに
- 可読性: プレフィックスで変更内容が即座に理解可能
- 簡潔性: 50文字以内に収まる適切な長さ
- 検索性: プレフィックスでフィルタリングが容易に
実装のコツ
- 具体的な例を提供: Good/Bad例を示すことでAIの理解度が向上
- 文字数制限を明記: "including the prefix"と明記することが重要
- 言語の統一: コミットメッセージは英語で統一し、コメントは案件に応じて言語を選択
まとめ
Cursor AIのRulesファイルでコミットメッセージのルールを明確にすることで、プロジェクト全体のコミット履歴が格段に見やすくなりました。特にAngular Conventionのプレフィックスルールを採用したことで、変更の種類が一目瞭然に。
これにより:
- コードレビューの効率が向上
- 変更履歴の追跡が容易に
- チーム全体でのコミット品質の統一
小さな設定変更ですが、開発体験の向上に大きく貢献しています。皆さんのプロジェクトでも、ぜひ.cursorrules
ファイルを活用してみてください!
Discussion