Commit message — это подпись к вашему снимку кода! От него зависит насколько понятна история проекта.
Формула хорошего сообщения
<type>: <short description>
[optional longer description]
[optional footer]
Типы (type):
- feat — новая функция
- fix — исправление бага
- docs — документация
- refactor — рефакторинг без изменения поведения
- test — тесты
- chore — рутинные задачи
- style — форматирование кода
Примеры отличных сообщений
✅ feat: add user authentication
✅ fix: resolve crash on empty input
✅ docs: update API documentation
✅ refactor: simplify database queries
✅ test: add unit tests for login
✅ chore: update dependencies
Примеры плохих сообщений
❌ update
❌ fix
❌ done
❌ asdf
❌ commit
❌ работа
Почему плохо: Через месяц ВЫ не вспомните что делали!
Правила написания
1. Первая строка — краткое описание (50 символов)
# ✅ Хорошо
feat: добавлена двухфакторная аутентификация
# ❌ Плохо (слишком длинно)
feat: добавлена супер крутая двухфакторная аутентификация с поддержкой SMS и email и еще кучей всего
2. Используйте повелительное наклонение
# ✅ Правильно
fix: resolve memory leak in cache
feat: add export to PDF
docs: update installation guide
# ❌ Неправильно
fix: resolved memory leak
feat: added export to PDF
docs: updated installation guide
Почему: Коммит делает изменение, а не описывает что вы сделали.
3. Отделяйте заголовок от тела пустой строкой
git commit -m "feat: add payment processing
Integrate Stripe API for payments.
Support credit cards and bank transfers. Support refunds and webhooks.
"
4. Объясняйте “почему”, а не “что”
❌ Плохо (описывает ЧТО):
fix: change timeout from 30 to 60
✅ Хорошо (объясняет ПОЧЕМУ):
fix: increase API timeout to prevent failures
30 seconds was too short for slow connections.
Users in remote areas experienced timeouts.
Increased to 60s based on metrics.
Шаблон commit message
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
Пример:
fix(auth): prevent duplicate user registration
Modified the registration endpoint to check for existing email
before creating a new user. Added unique constraint on email field
in database schema.
Fixes #453
Когда использовать подробное описание?
Краткого достаточно:
docs: fix typo in README
style: format code with prettier
chore: update package.json
Нужно подробное:
refactor: redesign authentication flow
Old flow had security vulnerabilities:
- Session tokens stored in localStorage
- No CSRF protection
- Weak password requirements
New implementation:
- HttpOnly cookies for tokens
- CSRF tokens on all forms
- Enforced password complexity
- Rate limiting on login attempts
Breaking change: Need to clear browser data after update.
BREAKING CHANGE: Auth API changed from v1 to v2
Примеры по типам
feat (новая функция)
feat: add dark mode theme
feat: implement real-time notifications
feat(api): add GraphQL support
fix (баг-фикс)
fix: resolve crash on iOS Safari
fix: prevent XSS in user input
fix(payment): handle declined cards properly
docs (документация)
docs: add deployment guide
docs: update API examples
docs(readme): add badges and shields
refactor
refactor: extract validation to separate module
refactor: use async/await instead of callbacks
refactor(db): optimize query performance
test
test: add unit tests for auth service
test: increase code coverage to 80%
test(api): add integration tests
chore
chore: update dependencies
chore: configure CI/CD pipeline
chore(git): add .gitignore rules
Linking к issues и tasks
# Ссылка на issue
fix: resolve login timeout issue
Fixes #123
# Breaking change
feat!: redesign API authentication
BREAKING CHANGE: API v1 deprecated, use v2 endpoints
GitHub автоматически:
- Свяжет коммит с issue
- Закроет issue при merge (Fixes #123)
- Покажет линк в интерфейсе
Conventional Commits емодзи (опционально)
Некоторые команды используют emoji:
✨ feat: add new feature
🐛 fix: bug fix
📝 docs: documentation
♻️ refactor: code refactoring
✅ test: testing
🔧 chore: configuration
💄 style: styling
Пример:
git commit -m "✨ feat: add user profile page"
Инструменты для проверки
Commitlint — автоматическая проверка:
npm install --save-dev @commitlint/cli @commitlint/config-conventional
Husky — проверка перед коммитом:
npx husky add .husky/commit-msg 'npx commitlint --edit $1'
Commit message checklist
- [ ] Начинается с типа (feat, fix, docs, etc.)
- [ ] Первая строка < 50 символов
- [ ] Повелительное наклонение (“add” not “added”)
- [ ] Понятно что изменилось
- [ ] Если сложно — добавлено подробное описание
- [ ] Ссылка на issue/task если есть
- [ ] Нет опечаток
Примеры отличных историй коммитов
Django проект:
feat: add user authentication system
feat: create registration form
feat: implement email verification
fix: resolve CSRF token mismatch
test: add auth tests
docs: update README with auth setup
refactor: extract email sender to service
chore: add Django extensions
Заключение
Хорошие commit messages — признак профессионала!
Работодатели смотрят на ваш GitHub. Пишите сообщения так, будто их читает ваш босс! 💼
Помните:
1. Тип + краткое описание
2. Повелительное наклонение
3. Объясняйте “почему”
4. Ссылайтесь на issues
Начните прямо сейчас — следующий коммит сделайте правильно! ✍️
💬 Comments (0)
No comments yet
Be the first to share your opinion about this article!