[Git] git commit message template ์ ์ฉํ๊ธฐ
์ด์ ํฌ์คํ (https://kkangsg.tistory.com/95)์์ commit message convention์ ๋ํด ์์๋ณด์๋ค.
์ด๋ฒ ํฌ์คํ ์์๋
ํด๋น convention์ ๋ฐ๋ฅด๋ Git commit message template ์ ์ฒด๋ฅผ ์ดํด๋ณด๊ณ
global๊ณผ local์ ์ ์ฉํด์ ์์ผ๋ก ๋์ ํ๋ก์ ํธ์ commit message template์ ์ ์ฉํ๋๋ก ํ๊ฒ ๋ค.๐ง
1. commit message template ์๊ฐ
๋๋ ์๋์ ๊ฐ์ ์ปค๋ฐ ๋ฉ์์ง ํ ํ๋ฆฟ์ ์ฌ์ฉํ๊ณ ์๋ค. Gitmoji๋ฅผ ์ฌ์ฉํ๊ณ ์ฐธ๊ณ ํด์ผํ ๋ถ๋ถ๋ค์ ์ถ๊ฐ๋ก ์ ์ด์ฃผ์๋ค.
(ํ ํ๋ฆฟ์ ๋ด์ฉ์ด ์ ์ด๋ ๊ฒ ๊ตฌ์ฑ๋์๋์ง ์๊ณ ์ถ๋ค๋ฉด ์ด์ ํฌ์คํ (convention)์ ๋ํด ์ฐธ๊ณ ํ๋ฉด ๋๋ค)
################
# <ํ์
> : <์ ๋ชฉ> ์ ํ์์ผ๋ก ์ ๋ชฉ์ ์๋ ๊ณต๋ฐฑ์ค์ ์์ฑ
# ์ ๋ชฉ์ 50์ ์ด๋ด / ๋ณ๊ฒฝ์ฌํญ์ด "๋ฌด์"์ธ์ง ๋ช
ํํ ์์ฑ / ๋์ ๋ง์นจํ ๊ธ์ง
# ์) :sparkles:Feat : ๋ก๊ทธ์ธ ๊ธฐ๋ฅ ์ถ๊ฐ # ์ด์๋ฒํธ
# ๋ฐ๋ก ์๋ ๊ณต๋ฐฑ์ ์ง์ฐ์ง ๋ง์ธ์ (์ ๋ชฉ๊ณผ ๋ณธ๋ฌธ์ ๋ถ๋ฆฌ๋ฅผ ์ํจ)
################
# ๋ณธ๋ฌธ(๊ตฌ์ฒด์ ์ธ ๋ด์ฉ)์ ์๋ซ์ค์ ์์ฑ
# ์ฌ๋ฌ ์ค์ ๋ฉ์์ง๋ฅผ ์์ฑํ ๋ "-"๋ก ๊ตฌ๋ถ (ํ ์ค์ 72์ ์ด๋ด)
# '์'๋ผ๋ ๊ฒ์ ์ด์ ์ ๋ง์ถฐ ์์ฑ
################
# ๊ผฌ๋ฆฟ๋ง(footer)์ ์๋ซ์ค์ ์์ฑ (ํ์ฌ ์ปค๋ฐ๊ณผ ๊ด๋ จ๋ ์ด์ ๋ฒํธ ์ถ๊ฐ ๋ฑ)
# ํด๊ฒฐ -> Closes(์ข
๋ฃ), Fixes(์์ ), Resolves(ํด๊ฒฐ)
# ์ฐธ๊ณ -> Ref(์ฐธ๊ณ ), Related to(๊ด๋ จ), See also(์ฐธ๊ณ )
# ์) Close #7
################
# :tada:Init: ํ๋ก์ ํธ ๊ฐ์
# :sparkles:Feat : ์๋ก์ด ๊ธฐ๋ฅ ์ถ๊ฐ
# :bug:Fix : ๋ฒ๊ทธ ์์
# :fire:Remove : ์ฝ๋ ์ญ์
# :memo:Docs : ๋ฌธ์ ์์
# :white_check_mark:Test : ํ
์คํธ ์ฝ๋, ๋ฆฌํฉํ ๋ง ํ
์คํธ ์ฝ๋ ์ถ๊ฐ
# :recycle:Refact : ์ฝ๋ ๋ฆฌํฉํ ๋ง
# :rocket:Deploy : ๋ฐฐํฌ
# :hammer:Chore : ๋น๋ ์
๋ฌด ์์ , ํจํค์ง ๋งค๋์ ์์
################
:tada:, :sparkles: ๋ฑ ์ด ์๋ฏธํ๋ ๋ฐ๋ emoji์ด๋ค.
2. .gitmessage ํ์ผ ๋ง๋ค๊ธฐ
ํ ํ๋ฆฟ ํ์ผ์ ๋ง๋๋ ๋ฐฉ๋ฒ์ ํฌ๊ฒ 2๊ฐ์ง๊ฐ ์๋ค.
1๏ธโฃ VSC ๊ฐ์ ์๋ํฐ ์์์ ์ง์ txt ํ์ผ์ ์์ฑํ๊ณ ์์ template ๋ด์ฉ์ ๋ณต๋ถํ๋ค.
2๏ธโฃ bash shell์์ vi ๋๋ vim ํธ์ง๊ธฐ๋ฅผ ์ด์ฉํด์ ๋ง๋ ๋ค.
step1) ์ํ๋ ๋๋ ํ ๋ฆฌ ์์น๋ก ์ด๋ํ๋ค.
cd /path/user/project
step2) vi ํธ์ง๊ธฐ๋ก ๋ง๋ค๊ณ ์ ํ๋ ํ์ผ์ ์ฐ๋ค (ํด๋น ํ์ผ์ด ์์ด๋ ์ด ์ ์๋ค = ์์์์ฑ)
vi .gitmessage
(ํ์ผ๋ช ๋ค์ .txt ํ์ฅ์ ์ด๋ฆ์ ์ ํ์ด๋ค. ์ผ๋ฐ์ ์ผ๋ก ๋ถ์ฌ์ฃผ๋ ๊ฒ ๊ฐ์๋ฐ ๋๋ ์ ๋ถ์ฌ์คฌ๋ค.)
step3) vi ํธ์ง๊ธฐ๊ฐ ์ด๋ฆฌ๋ฉด 'i'ํค๋ฅผ ๋๋ฌ์ 'ํ ์คํธ ์ ๋ ฅ ๋ชจ๋'๋ก ๋ณ๊ฒฝํ ํ, ์์ template ๋ด์ฉ์ ์ ๋ ฅํ๋ค. (๋ณต๋ถํ๋ค)
step4) ์ ๋ ฅ์ด ์๋ฃ๋๋ฉด 'esc'๋ฅผ ๋๋ฌ์ ํ ์คํธ ์ ๋ ฅ ๋ชจ๋๊ฐ ์๋ ๋ทฐ์ด ๋ชจ๋๋ก ์ ํํด์ฃผ๊ณ , ':wq'๋ฅผ ์ ๋ ฅํด์ ์ ์ฅ ๋ฐ ์ข ๋ฃํด์ค๋ค.
3. git commit template ์์คํ ์ค์ ํ๊ธฐ
์๋๋ $ git commit -m "writing commit message" ํด๋น ๋ช ๋ น์ด๋ฅผ ํตํด ์ปค๋ฐ๋ฉ์์ง๋ฅผ ์์ฑํ๋ค๋ฉด
์ด์ ๋
$ git config [optional] commit.template [path of template]
์์ ๊ฐ์ ๋ช ๋ น์ด๋ฅผ ํตํด
$ git commit ๋ช ๋ น์ด๋ฅผ ๊น์ง๋ง ์์ฑํด๋, ์ฐ๋ฆฌ๊ฐ ๋ง๋ 'commit message tamplate ์ ๋ฌธ'์ด ๋ณด์ด๋๋ก ์ค์ ํ ๊ฒ์ด๋ค.
์์ ๋ช ๋ น์ด์ ๋ํด ํ๋์ฉ ์ดํด๋ณด์ (๋ช ๋ น์ด ํด์)
1๏ธโฃ $ git config
git์ ์ค์ ์ ๋ณ๊ฒฝํ๋ ๋ช ๋ น์ด
2๏ธโฃ $ [optional]
์ด ๋ถ๋ถ์๋ --global , --local , --system ์ ๋ช ๋ น์ด๊ฐ ๋ค์ด๊ฐ ์ ์๋ค.
[1] --global ์ธ ๊ฒฝ์ฐ
$ git config --global commit.template [path of template]
ํด๋น git ์ค์ ์ ์ ์ญ์ผ๋ก ๋ณ๊ฒฝํ๊ฒ ๋ค.
์ฆ, ํด๋น ์ฌ์ฉ์์ ๋ชจ๋ GIT ํ๋ก์ ํธ์ ์ ์ฉ๋๋ค.
[2] --local ์ธ ๊ฒฝ์ฐ
$ git config --local commit.template [path of template]
ํด๋น git ์ค์ ์ ์ง์ญ์ผ๋ก ๋ณ๊ฒฝํ๊ฒ ๋ค.
์ฆ, ํด๋น ์ฌ์ฉ์๊ฐ ํ์ฌ ์์ ์ค์ธ GIT ํ๋ก์ ํธ๋ง ์ ์ฉ๋๋ค.
ํ๋ก์ ํธ ๋ด์์๋ง ์ค์ ์ด ์ ํจํ๊ณ , ์ธ๋ถ ํ๋ก์ ํธ์์๋ ํด๋น git ์ค์ ์ ์ฌ์ฉํ ์ ์๋ค.
[3] --system ์ธ ๊ฒฝ์ฐ (์ฌ์ฉํ๊ธธ ๊ถ์ฅํ์ง ์์! ๋ง์ฝ ๊ผญ ์ฌ์ฉํ๋ค๋ฉด ์กฐ์ฌํด์ ์ฌ์ฉํด์ผ ํ๋ค!)
$ git config --system commit.template [path of template]
ํด๋น git ์ค์ ์ด ์์คํ ์ ์ฒด์ ์ ์ฉ๋๋ค.
์ฆ, ๋ชจ๋ ์ฌ์ฉ์ ๋ฐ ๋ชจ๋ GIT ํ๋ก์ ํธ์ ์ ์ฉ๋๋ค.
(*์ผ๋ฐ์ ์ผ๋ก ์์คํ ์ ์ฒด ์ค์ ์ ๋ณ๊ฒฝํ๊ธฐ ์ํด์๋ ๊ด๋ฆฌ์ ๊ถํ(sudo)์ด ํ์ํ๋ค.)
์์คํ ๋ ๋ฒจ ์ค์ ์ ๋ณ๊ฒฝํ๋ ๊ฒ์ ์ฃผ์ํด์ผ ํ๊ณ , ๊ผญ ํ์ํ ๊ฒฝ์ฐ์๋ง ์ฌ์ฉํด์ผ ํ๋ค.
๊ฐ์ธ ํ๋ก์ ํธ๋ ํ ํ๋ก์ ํธํ ๋๋ ์ ์ญ/์ง์ญ ์ค์ ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ผ๋ฐ์ ์ด๋ค.
4๏ธโฃ $ commit.template [path of template]
ํด๋น ๊ฒฝ๋ก ์์น์ ์๋ ํ ํ๋ฆฟ ํ์ผ์ ์ปค๋ฐ ๋ฉ์์ง ํ ํ๋ฆฟ์ผ๋ก ์ง์ ํ๋ ๋ช ๋ น์ด
๋ฐ๋ผ์ ์์ ๋ช ๋ น์ด๋ฅผ ๋ณธ์ธ ํ๋ก์ ํธ์ ๋ง๊ฒ ์์ฑํ๋ฉด ๋๋ค.๐ง
์ฌ๊ธฐ๊น์ง ์์ ์ด ์๋ฃ๋์๋ค๋ฉด $ git add ๋ช ๋ น์ด ๋ก staging area์ ์ด๋์ํจ ๋ค
์๊ฒฉ์ ์ฅ์์ ์ ์ฅํ๊ธฐ ์ํด $ git commit ๋ช ๋ น์ด๋ก ๋ฉ์์ง ํ ํ๋ฆฟ์ด ์๋ํฐ์์ ์ด๋ฆฌ๋์ง ํ์ธํด๋ณด์๐
[์ค์ต]
๋๋ ์์ ๊ฐ์ด ํ๋ก์ ํธ ๋ด๋ถ์ .gitmessage๋ฅผ ์์ฑํด์ฃผ์๊ณ , ํด๋น ํ๋ก์ ํธ์์๋ง ์ ์ฉํ๊ณ ์ถ๊ธฐ ๋๋ฌธ์
.gitmessage๊ฐ ์๋ ์์น์์ ์๋ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ์๋ค.
$ git config --local commit.template .gitmessage
์๋ฌด๊ฒ๋ ๋์ค์ง ์์ผ๋ฉด ์ ์ค์ ๋ ๊ฒ์ด๋ค.
git add ์ดํ, git commit ๋ช ๋ น์ด ์ ๋ ฅํ๋ฉด ์๋์ ๊ฐ์ด
'hint: Waiting for your editor to close the file... '์ด๋ผ๋ ํํธ๊ฐ ๋์ค๋ฉด์
COMMIT_EDITMSG ๊ฐ ๋์ค๊ฒ ๋๋ค.
์์ ๊ฐ์ด ๋์จ ํ ํ๋ฆฟ์ ์์ ํ์ฌ (#๊ฐ ์์ผ๋ฉด ์ฃผ์์ผ๋ก ์ธ์๋์ด ์ ์ฅ์ด ์ ๋จ)
git commit message๋ฅผ ์์ฑํ๋ฉด ๋๋ค!!!!
์ค์ต ๋!๐
[์ฐธ๊ณ ]
- Git Convension
- Gitmoji ์ฌ์ฉ
- Git commit message template
https://velog.io/@ye-ji/Git-PR-%EC%9E%98-%EC%93%B0%EB%8A%94-%EB%B0%A9%EB%B2%95