Git

[Git] commit message convention - 커밋 메시지 컨벤션

은하비 2023. 5. 18. 18:33

협업을 하기 위해 git을 이용할 때 구성원들 끼리 commit message의 양식을 통일하지 않는다면 혼란한 git log들과 추적하기 힘든 history를 만날 확률이 높습니다. 따라서 협의를 통해 양식을 가지고 commit message를 작성하는 것이 좋은데, 이때 널리 사용되는 Udacity style에 대해 알아보겠습니다.

Udacity git commit message style

Udacity Git Commit Message Style Guide에서 제공한 commit message style에 대한 가이드에 따르면 커밋 메시지의 구조는 비어있는 줄로 구분되는 3가지의 영역으로 나뉩니다.

type: Subject

body

footer

type

타입은 아래 중 한가지를 갖습니다.

type명 내용
feat 새로운 기능이 있을 때
fix 버그 수정
docs 문서 내용을 수정할 때
style 포맷의 변경, 세미콜론 누락 등 코드 변화가 없을 때
refector 코드를 리팩터링할 때
test 프로덕션 코드 변경이 없는 테스트 코드의 추가, 리팩터링의 테스트
chore 프로덕션 코드 변경이 없는 빌드 태스크 업데이트, 패키지의 config 변경

Subject

type+콜론+띄어 쓰기 한 칸 후 50자 이내로 작성하고, 끝낼 때 마침표를 작성하지 않습니다. 영어로 작성 시 시작 글자는 대문자로 하고 명령형 어조로 작성합니다. 

Body

모든 commit에 작성할 필요는 없고 복잡한 내용 설명이 필요한 commit에만 선택적으로 작성합니다. 커밋의 내용과 이유를 작성합니다. 본문을 작성하려면 제목 사이에 한 줄을 빈줄로 넣어 구분하고 각 줄의 길이가 72자 이내로 작성되어야합니다.(영문 기준)

Footer

footer 또한 선택사항이며 Issue tag 번호를 적는것이 일반적입니다.

Udacity Commit Message Example

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

Reference

1) Udacity Manodegree Style Giude, Udacity Git Commit Message Style Guide, https://udacity.github.io/git-styleguide/