Git

[Git] 깃 커밋 메시지 컨벤션 (Git Commit Message Convention)

da-nyee 2020. 7. 3. 15:21

개요

Git의 개념을 접하고 사용한지 1년 정도 됐다.
작년 여름에 집중적으로 공부했었는데, 그때는 공책에 필기로 정리해두고 따로 블로그에 글을 쓸 생각을 안했다.
이제 곧 종강이기도 하고, 복습할 겸 Git 개념이나 명령어 등을 블로그에 포스팅할 생각이다.

Git 커밋 메시지를 작성하면서 나름대로 하나의 관습을 따르고 있다.
그런데, 이 관습에 명칭이 있는지 어제 처음 알았다.. 바로 Udacity style.
명칭을 알게 된 기념으로 Udacity style이 무엇인지 글로 남겨보고자 한다.

Udacity style?

Udacity style의 커밋 메시지 구조는 아래와 같이 생겼다.

type: subject

body

footer

subject, body, footer에 들어가는 내용을 하나하나 살펴보자.

Title

커밋 메시지 제목은 docs: Update README.md처럼 작성한다.
docs는 제목의 종류이고, Update README.md는 제목의 주제이다.

Subject

제목의 주제는 크게 4가지의 특징을 가진다.

  • 길이는 50자 이하로 작성한다.
  • 동사원형(ex. Add, Update, Modify)로 시작한다.
  • 첫 글자는 대문자이다.
  • 끝에는 마침표를 붙이지 않는다.

Type

제목의 종류는 크게 7가지가 있다.

  • feat: 새로운 기능 추가
  • fix: 버그 수정
  • docs: 문서 수정
  • style: 코드 포맷 변경, 세미콜론 누락, 코드 변경 없음
  • refactor: 프로덕션 코드 리팩터링
  • test: 테스트 추가, 테스트 리팩터링, 프로덕션 코드 변경 없음
  • chore: 빌드 테스크 업데이트, 패키지 매니저 환경설정, 프로덕션 코드 변경 없음

Body

커밋 메시지는 대부분 제목만 읽어도 내용을 파악할 수 있다.
따라서, 바디는 선택사항으로 커밋 메시지에 부가적인 설명이 필요할 때 작성한다.


바디는 크게 3가지의 특징을 가진다.

  • 길이는 72자 이하로 작성한다.
  • 제목과 바디 사이에는 한 줄의 공백을 추가한다.
  • 커밋 메시지의 whatwhy에 대해 작성한다. how는 고려하지 않는다.

Footer

푸터 역시 선택사항이다.
해결한 이슈 커밋의 ID, 해결하기 위해 참고한 커밋의 ID 등을 작성한다.

예시

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 consequenses 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

참조

Udacity Git Commit Message Style Guide