Git Commit Message Convention
커밋 메시지를 작성할 때 사용자 간 원활한 소통을 위해 일관된 형식
커밋 메시지 형식
제목 type: Subject
본문 body
꼬리말 footer
기본적으로 3가지 영역(제목, 본문, 꼬리말)으로 나누어졌다.
Commit Type
type은 아래와 같이 분류된다. 아래와 같이 소문자로 작성한다.
feat
: 새로운 기능 추가fix
: 버그 수정docs
: 문서 내용 변경style
: 포맷팅, 세미콜론 누락, 코드 변경이 없는 경우 등refactor
: 코드 리팩토링test
: 테스트 코드 작성chore
: 빌드 수정, 패키지 매니저 설정, 운영 코드 변경이 없는 경우 등
Subject (제목)
- 제목은 50글자 이내로 작성한다.
- 첫글자는 대문자로 작성한다.
- 마침표 및 특수기호는 사용하지 않는다.
- 영문으로 작성하는 경우 동사(원형)을 가장 앞에 명령어로 작성한다.
- 과거시제는 사용하지 않는다.
- 간결하고 요점적으로 즉, 개조식 구문으로 작성한다.
Fixed(X) → fix (O)
Body (본문)
- 72이내로 작성한다.
- 최대한 상세히 작성한다. (코드 변경의 이유를 명확히 작성할수록 좋다)
- 어떻게 변경했는지보다 무엇을, 왜 변경했는지 작성한다.
Footer (꼬리말)
- 선택사항
- issue tracker ID 명시하고 싶은 경우에 작성한다.
- 유형: #이슈 번호 형식으로 작성한다.
- 여러 개의 이슈번호는 쉼표(,)로 구분한다.
- 이슈 트래커 유형은 다음 중 하나를 사용한다.
- Fixes: 이슈 수정중 (아직 해결되지 않은 경우)
- Resolves: 이슈를 해결했을 때 사용
- Ref: 참고할 이슈가 있을 때 사용
- Related to: 해당 커밋에 관련된 이슈번호 (아직 해결되지 않은 경우)
커밋 메시지 예시
feat: Summarize changes in around 50 characters or less
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.
Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequences of this
change? Here's the place to explain them.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded
by a single space, with blank lines in between, but conventions
vary here
If you use an issue tracker, put references to them at the bottom,
like this:
Resolves: #123
See also: #456, #789
COMMIT MESSAGE SETTING
커밋 메시지 편집기로 처리
(-m
or -F
옵션을 통해 커밋 메시지를 지정하는 경우에는 편집기가 뜨지 않는다.)
git config --global core.editor "code --wait"
Git 커밋 메시지 템플릿 지정
// 전역 설정
git config --global commit.template <template_file_path>
// 프로젝트 개별로 템플릿 설정
git config commit.template <template_file_path>
// 설정 해제
git config --unset --global commit.template
.gitmessage.txt
내용 작성 예시
################
# <타입> : <제목> 의 형식으로 제목을 아래 공백줄에 작성
# 제목은 50자 이내 / 변경사항이 "무엇"인지 명확히 작성 / 끝에 마침표 금지
# 예) feat : 로그인 기능 추가
# 바로 아래 공백은 지우지 마세요 (제목과 본문의 분리를 위함)
################
# 본문(구체적인 내용)을 아랫줄에 작성
# 여러 줄의 메시지를 작성할 땐 "-"로 구분 (한 줄은 72자 이내)
################
# 꼬릿말(footer)을 아랫줄에 작성 (현재 커밋과 관련된 이슈 번호 추가 등)
# Fixes: 이슈 수정중 (아직 해결되지 않은 경우)
# Resolves: 이슈를 해결했을 때 사용
# Ref: 참고할 이슈가 있을 때 사용
# Related to: 해당 커밋에 관련된 이슈번호 (아직 해결되지 않은 경우)
# 예) Resolves #7
################
# feat : 새로운 기능 추가
# fix : 버그 수정
# docs : 문서 수정
# test : 테스트 코드 추가
# refact : 코드 리팩토링
# style : 코드 의미에 영향을 주지 않는 변경사항
# chore : 빌드 부분 혹은 패키지 매니저 수정사항
################
기타 에디터 명령어
참고
https://velog.io/@archivvonjang/Git-Commit-Message-Convention
https://udacity.github.io/git-styleguide/
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---templateltfilegt
https://ekko.tistory.com/50
'git & github' 카테고리의 다른 글
git Patch 생성과 적용 (2) | 2025.01.03 |
---|---|
git hook 정리 (0) | 2025.01.03 |
git github 처음부터 다시 배우기 - 6. git hub 활용 (0) | 2023.02.15 |
git github 처음부터 다시 배우기 - 5. git 활용 (0) | 2023.02.13 |
git github 처음부터 다시 배우기 - 3. git 디테일 (0) | 2023.02.13 |