포스트

[GitHub 100일 챌린지] Day 30 - 커밋 메시지 작성법

[GitHub 100일 챌린지] Day 30 - 커밋 메시지 작성법

100일 챌린지 Day 30 - 좋은 커밋 메시지로 협업 품질을 높입니다

배울 내용

  1. 좋은 커밋 메시지 7가지 규칙
  2. 커밋 메시지 컨벤션
  3. 실전 메시지 작성 예시

Topic1. 좋은 커밋 메시지 7가지 규칙

좋은 커밋 메시지 = 프로젝트 문서

7가지 규칙

1. 제목과 본문을 빈 줄로 분리

1
2
3
4
5
Add user authentication

Implement JWT-based authentication system
with refresh token support and role-based
access control.

2. 제목은 50자 이내

1
2
✅ Add user authentication feature
❌ Add user authentication feature with JWT and refresh token support

3. 제목 첫 글자는 대문자

1
2
✅ Fix login button bug
❌ fix login button bug

4. 제목 끝에 마침표 금지

1
2
✅ Update README
❌ Update README.

5. 제목은 명령문으로

1
2
3
4
5
✅ Add feature
✅ Fix bug
❌ Added feature
❌ Fixed bug
❌ Adding feature

이유:

1
2
3
4
5
Git 자체가 명령문 사용
- Merge branch 'feature'
- Revert "Add feature"

일관성 유지 위해 명령문 권장

6. 본문은 72자마다 줄바꿈

1
2
3
Implement user authentication system using JWT tokens.
This provides secure session management and supports
refresh tokens for extended sessions.

7. 본문에는 “무엇을”, “왜”를 설명

1
2
3
4
5
6
7
8
9
❌ 나쁜 예:
Fixed bug

✅ 좋은 예:
Fix memory leak in user session

The session cleanup task was not properly
canceling when users logged out, causing
memory to accumulate over time.

해보기: 규칙 적용 연습

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# ❌ 나쁜 예
git commit -m "update"

# ✅ 좋은 예 (간단한 경우)
git commit -m "Update user profile validation"

# ✅ 좋은 예 (복잡한 경우)
git commit
# 에디터에서:
# Add user email verification
#
# Implement email verification flow:
# - Send verification email on signup
# - Verify token from email link
# - Update user status on success

결과: 7가지 규칙을 적용한 명확한 커밋 메시지를 작성합니다


Topic2. 커밋 메시지 컨벤션

프로젝트에서 자주 사용하는 메시지 형식입니다.

Conventional Commits

형식:

1
2
3
4
5
<type>(<scope>): <subject>

<body>

<footer>

Type 종류:

1
2
3
4
5
6
7
8
9
10
11
feat:     새 기능
fix:      버그 수정
docs:     문서 변경
style:    코드 포맷팅 (기능 변경 없음)
refactor: 리팩토링
test:     테스트 추가/수정
chore:    빌드, 설정 변경
perf:     성능 개선
ci:       CI/CD 설정
build:    빌드 시스템 변경
revert:   커밋 되돌리기

예시:

1
2
3
4
5
6
7
8
feat(auth): Add JWT authentication

Implement JWT-based auth system with:
- Token generation and validation
- Refresh token support
- Role-based access control

Closes #123

Scope 예시:

1
2
3
4
feat(auth): 인증 관련
feat(ui): UI 관련
feat(api): API 관련
feat(db): 데이터베이스 관련

한글 프로젝트 컨벤션

한글 사용 시:

1
2
3
4
5
타입: 제목

본문

푸터

타입 종류:

1
2
3
4
5
6
7
기능:     새 기능
수정:     버그 수정
문서:     문서 변경
스타일:   코드 포맷팅
리팩터링: 코드 개선
테스트:   테스트 추가
빌드:     빌드 설정

예시:

1
2
3
4
5
6
7
8
기능(인증): JWT 인증 시스템 추가

JWT 기반 인증 시스템 구현:
- 토큰 생성 및 검증
- 리프레시 토큰 지원
- 역할 기반 접근 제어

이슈 #123 해결

Gitmoji 사용

이모지로 타입 표시:

1
2
3
4
5
6
7
8
9
✨ feat:     새 기능
🐛 fix:      버그 수정
📝 docs:     문서
💄 style:    UI/스타일
♻️ refactor: 리팩토링
✅ test:     테스트
🔧 chore:    설정
⚡️ perf:     성능
🚀 deploy:   배포

예시:

1
2
3
git commit -m "✨ feat: Add dark mode toggle"
git commit -m "🐛 fix: Fix login validation bug"
git commit -m "📝 docs: Update API documentation"

해보기: 컨벤션 적용하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 1. Conventional Commits
git commit -m "feat(user): Add profile image upload

Allow users to upload profile images with:
- Image validation (size, format)
- Automatic resizing
- S3 storage integration

Closes #456"

# 2. Gitmoji
git commit -m "✨ Add profile image upload feature"

# 3. 한글 컨벤션
git commit -m "기능(사용자): 프로필 이미지 업로드 추가"

결과: 프로젝트 컨벤션에 맞는 일관된 커밋 메시지를 작성합니다


Topic3. 실전 메시지 작성 예시

다양한 상황별 커밋 메시지 예시입니다.

기능 추가

간단한 기능:

1
git commit -m "Add search functionality to user list"

복잡한 기능:

1
2
3
4
5
6
7
8
9
10
11
12
git commit
# 에디터:
feat: Add advanced search with filters

Implement comprehensive search system:
- Full-text search across name, email
- Date range filtering
- Status filtering (active/inactive)
- Results pagination (20 per page)
- Export to CSV

Related to #789

버그 수정

간단한 버그:

1
git commit -m "fix: Correct date format in user profile"

복잡한 버그:

1
2
3
4
5
6
7
8
9
10
11
12
13
git commit
# 에디터:
fix: Resolve memory leak in file upload

The upload component was not properly cleaning up
event listeners after file processing completed.
This caused memory to accumulate when users uploaded
multiple files in a session.

Solution: Added cleanup in useEffect return function
to remove all event listeners on component unmount.

Fixes #234

리팩토링

1
2
3
4
5
6
7
8
9
10
11
git commit
# 에디터:
refactor: Extract validation logic to separate module

Move user input validation from component to
dedicated validation utility. This improves:
- Reusability across components
- Testability of validation logic
- Separation of concerns

No functional changes.

문서 업데이트

README 업데이트:

1
git commit -m "docs: Update installation instructions"

API 문서:

1
git commit -m "docs: Add API endpoint documentation for user search"

성능 개선

1
2
3
4
5
6
7
8
9
10
11
git commit
# 에디터:
perf: Optimize database queries in user search

Replace multiple individual queries with single
JOIN query, reducing database round trips from
N+1 to 1. Performance improvement:
- Response time: 2000ms → 200ms
- Database load: 90% reduction

Benchmarked with 10,000 user records.

테스트 추가

1
2
3
4
5
6
7
git commit -m "test: Add unit tests for user validation

- Email format validation
- Password strength validation
- Required field validation

Coverage increased from 65% to 85%"

설정 변경

1
2
3
4
5
6
7
git commit -m "chore: Update dependencies to latest versions

- React 17 → 18
- TypeScript 4.5 → 4.9
- ESLint 7 → 8

All tests passing."

Breaking Changes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
git commit
# 에디터:
feat!: Change API response format

BREAKING CHANGE: User API now returns data in
different format.

Before:
{
  "user": { "name": "John" }
}

After:
{
  "data": {
    "user": { "name": "John" }
  }
}

Migration guide: docs/migration-v2.md

되돌리기

1
2
3
4
5
6
git commit -m "revert: Revert 'Add feature X'

This reverts commit abc123def456.

Feature X caused performance regression in
production. Reverting until issue is resolved."

실전 팁

DO (권장):

1
2
3
4
5
"Add user authentication""Fix login button alignment""Update README with new API docs""Refactor user service for better testability""Remove deprecated API endpoints"

DON’T (비권장):

1
2
3
4
5
"update""fix bug""changes""asdfasdf""WIP" (work in progress - 임시 커밋)

메시지 템플릿 설정:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 1. 템플릿 파일 생성
cat > ~/.gitmessage << EOF
# <type>(<scope>): <subject>
#
# <body>
#
# <footer>
#
# Type: feat, fix, docs, style, refactor, test, chore
# Scope: component or file name
# Subject: imperative, lowercase, no period
# Body: what and why (optional)
# Footer: issues, breaking changes (optional)
EOF

# 2. Git에 설정
git config --global commit.template ~/.gitmessage

# 3. 사용
git commit
# 템플릿이 열림

해보기: 다양한 상황 연습

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 1. 기능 추가
echo "search" > search.js
git add search.js
git commit -m "feat: Add user search functionality"

# 2. 버그 수정
echo "fix" > fix.js
git add fix.js
git commit -m "fix: Resolve search query encoding issue"

# 3. 문서 수정
echo "docs" > README.md
git add README.md
git commit -m "docs: Add search API documentation"

# 4. 리팩토링
echo "refactor" > utils.js
git add utils.js
git commit -m "refactor: Extract search logic to utils"

# 5. 히스토리 확인
git log --oneline

결과: 상황에 맞는 명확하고 일관된 커밋 메시지를 작성할 수 있습니다


정리

완료 체크:

  • 좋은 커밋 메시지 7가지 규칙을 알고 있다
  • 커밋 메시지 컨벤션을 사용할 수 있다
  • 상황에 맞는 실전 메시지를 작성할 수 있다

7가지 규칙:

1
2
3
4
5
6
7
1. 제목/본문 빈 줄로 분리
2. 제목 50자 이내
3. 제목 첫 글자 대문자
4. 제목 끝 마침표 금지
5. 제목은 명령문
6. 본문은 72자마다 줄바꿈
7. 본문에 "무엇"과 "왜"

컨벤션 형식:

1
2
3
4
5
<type>(<scope>): <subject>

<body>

<footer>

좋은 메시지 특징:

1
2
3
4
✅ 명확함: 무엇을 했는지 즉시 이해
✅ 일관성: 프로젝트 전체가 같은 형식
✅ 유용함: 나중에 히스토리 추적 가능
✅ 전문성: 협업 품질 향상

축하합니다! 🎉

Phase 3 완료! Git 로컬 작업의 기초를 모두 배웠습니다.

다음: Phase 4에서 원격 저장소와 협업을 배웁니다 →

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.