Conventional Commits는 커밋 메시지를 구조화된 형식으로 작성하는 사양이다. 자동 버전 관리, 변경 로그 생성, CI/CD 자동화를 위한 기계 가독성을 제공한다.
커밋 메시지 형식
<타입>[선택적 스코프]: <설명>
[선택적 본문]
[선택적 꼬리말]
타입 종류
| 타입 | 설명 | 버전 영향 |
|---|
| feat | 새 기능 추가 | minor (1.X.0) |
| fix | 버그 수정 | patch (1.0.X) |
| docs | 문서 변경만 | 없음 |
| style | 코드 스타일 (포매팅) | 없음 |
| refactor | 리팩터링 | 없음 |
| test | 테스트 추가/수정 | 없음 |
| chore | 빌드 도구, 의존성 | 없음 |
| BREAKING CHANGE | 하위 호환성 깨짐 | major (X.0.0) |
커밋 예시
bash
# 새 기능
git commit -m "feat(auth): add social login with Google OAuth"
# 버그 수정
git commit -m "fix(cart): correct total price calculation with discount"
# Breaking Change
git commit -m "feat(api)!: remove deprecated /v1 endpoints
BREAKING CHANGE: All /v1 API endpoints have been removed.
Migrate to /v2 endpoints. See MIGRATION.md for details."
# 여러 스코프 영향
git commit -m "refactor: extract shared utility functions to lib/"
commitlint 설정
javascript
// commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', [
'feat', 'fix', 'docs', 'style', 'refactor',
'test', 'chore', 'ci', 'perf', 'revert'
]],
'scope-case': [2, 'always', 'lower-case'],
'subject-max-length': [2, 'always', 72],
},
};
bash
# commitlint을 commit-msg 훅으로 설치
npm install --save-dev @commitlint/cli @commitlint/config-conventional
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1'
관련 문서