๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป ์ƒ์‚ฐ์„ฑ

[Git] git ์ดˆ๊ธฐ ์„ธํŒ…

by ye-ha 2022. 2. 5.

์„ธํŒ…

ํ„ฐ๋ฏธ๋„์—์„œ git config --global -e ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. ํ˜„์žฌ ์ ‘์† ์ค‘์ธ ์‚ฌ์šฉ์ž์˜ ์„ค์ •์„ ๋ณ€๊ฒฝํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
.gitconfig ํŒŒ์ผ์ด ์—ด๋ฆฌ๋ฉด ํŒŒ์ผ ๋‚ด์— ์•„๋ž˜ ๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

[user]
    name = your name
    email = your email

[push]
    default = current

[pull]
    rebase = true

[alias]
    hist = log --graph --all --pretty=format:'%C(yellow)[%ad]%C(reset) %C(green)[%h]%C(reset) | %C(white)%s %C(bold red){{%an}}%C(reset) %C(blue)%d%C(reset)' --date=short
    
[commit]
	template = ~/.gitcommitmessage.txt

์ œ๊ฐ€ ํ•ญ์ƒ ์‚ฌ์šฉํ•˜๋Š” ์•„์ฃผ ์ดˆ๊ธฐ ์„ธํŒ…์ž…๋‹ˆ๋‹ค.

์•ŒํŒŒ๋ฒณ a๋ฅผ ๋ˆ„๋ฅด๋ฉด ์ž…๋ ฅ ๋ชจ๋“œ๋กœ ๋ฐ”๋€๋‹ˆ๋‹ค. ๋ชจ๋‘ ์ž…๋ ฅํ–ˆ๋‹ค๋ฉด esc๋ฅผ ๋ˆŒ๋Ÿฌ์„œ ์ž…๋ ฅ ๋ชจ๋“œ์—์„œ ๋‚˜๊ฐ€์•ผ ํ•ฉ๋‹ˆ๋‹ค.
: ์„ ๋ˆ„๋ฅธ ํ›„ w (์ €์žฅ), q (์ข…๋ฃŒ)๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์—”ํ„ฐ๋ฅผ ์น˜๋ฉด ์ €์žฅ ํ›„ ์ข…๋ฃŒ๋ฉ๋‹ˆ๋‹ค.

 


1. ์‚ฌ์šฉ์ž ์ด๋ฆ„, ์ด๋ฉ”์ผ

[user]
    name = your name
    email = your email

 

2. push, pull

[push]
    default = current
[pull]
    rebase = true

์ €๋Š” ์œ„์™€ ๊ฐ™์€ ์˜ต์…˜์„ ์ฃผ๊ณ  ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. push์— ์–ด๋–ค ๊ฐ’๋„ ์ฃผ์ง€ ์•Š์„ ๊ฒฝ์šฐ git push ๋ฅผ ์ž…๋ ฅํ•  ๋•Œ๋งˆ๋‹ค ์–ด๋–ค ๋ธŒ๋žœ์น˜์— ํ•˜๊ฒ ๋‹ค๋Š” ๊ฑด์ง€ ์ง€์ •ํ•ด๋‹ฌ๋ผ๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๋œน๋‹ˆ๋‹ค. current๋Š” ํ˜„์žฌ ๋กœ์ปฌ์—์„œ ์ž‘์—…ํ•˜๊ณ  ์žˆ๋Š” ๋ธŒ๋žœ์น˜์™€ ๊ฐ™์€ ์ด๋ฆ„์˜ ๋ธŒ๋žœ์น˜๋ฅผ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.
pullํ•  ๋•Œ ๊ธฐ๋ณธ์ ์œผ๋กœ rebase๋˜๋„๋ก ์„ค์ •ํ•ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ถ€๋ถ„์€ ๋‹ค๋ฅธ ํฌ์ŠคํŒ…์œผ๋กœ ๋‹ค๋ฃจ๊ฒ ์Šต๋‹ˆ๋‹ค.

 

3. commit log๋ฅผ ๋ณด๊ธฐ ์ข‹๊ฒŒ

[alias]
    hist = log --graph --all --pretty=format:'%C(yellow)[%ad]%C(reset) %C(green)[%h]%C(reset) | %C(white)%s %C(bold red){{%an}}%C(reset) %C(blue)%d%C(reset)' --date=short

commit log๋ฅผ ์•Œ๋ก๋‹ฌ๋กํ•˜๊ฒŒ ๊พธ๋ฉฐ ๊ฐ€๋…์„ฑ์„ ์กฐ๊ธˆ ๋” ๋†’์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. git hist ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์•Œ๋ก๋‹ฌ๋กํ•œ log๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (q ๋ˆŒ๋Ÿฌ์„œ ๋‚˜๊ฐ€์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.)

 

4. ์ปค๋ฐ‹ ๋ฉ”์„ธ์ง€ ์ž‘์„ฑ ์‹œ ์ง€์ •ํ•œ ํŒŒ์ผ ๋ณด์ด๊ธฐ 

[commit]
	template = ~/.gitcommitmessage.txt

์ปค๋ฐ‹ ๋ฉ”์„ธ์ง€๋ฅผ ์ž‘์„ฑํ•  ๋•Œ, ์ œ๊ฐ€ ์ •ํ•œ ๊ทœ์น™์ด ํ•จ๊ป˜ ๋œจ๋„๋ก ์„ค์ •ํ•ด๋‘๊ณ  ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. 

VSCode ํ™”๋ฉด์ž…๋‹ˆ๋‹ค
.gitcommitmessage.txt
0.00MB

์ œ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ํŒŒ์ผ์„ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค. ์›ํ•˜๋Š” ํ˜•์‹์˜ ํŒŒ์ผ์„ ๋งŒ๋“œ์‹œ๊ณ , ํŒŒ์ผ์ด ์œ„์น˜ํ•œ ๊ณณ์„ .gitconfig file ๋‚ด์— ์•Œ๋งž๊ฒŒ ์ถ”๊ฐ€ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 

 

5. VSCode ๋ฅผ diff tool, merge tool๋กœ ์‚ฌ์šฉํ•˜๊ธฐ 

์ €๋Š” ์ปค๋ฐ‹ ๋ฉ”์„ธ์ง€ ์ž‘์„ฑ๊ณผ git์˜ diff, merge tool๋กœ VSCode๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. 4๋ฒˆ์˜ ์บก์ณ์™€ ๋˜‘๊ฐ™์ด ์„ค์ •ํ•˜๊ณ  ์‹ถ์œผ์‹œ๋‹ค๋ฉด VSCode ์„ค์น˜ ํ›„ ์•„๋ž˜์˜ ๋‚ด์šฉ๋„ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”. 

[core]
	editor = code --wait --diff $LOCAL $REMOTE
[diff]
    tool = vscode
[difftool "vscode"]
	cmd = code --wait --diff $LOCAL $REMOTE
	prompt = false
[merge]
    tool = vscode
[mergetool "vscode"]
    cmd = code --wait $MERGED

--wait ์˜ต์…˜์„ ์ฃผ๊ฒŒ ๋˜๋ฉด ์ˆ˜์ •/ํ™•์ธ ํ›„ ๋‹ค์‹œ ํ„ฐ๋ฏธ๋„๋กœ ๋Œ์•„์˜ฌ ๋•Œ๊นŒ์ง€ ํ„ฐ๋ฏธ๋„์ด ๋Œ€๊ธฐํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. 

๋Œ“๊ธ€