๊ด€๋ฆฌ ๋ฉ”๋‰ด

Daehyunii's Dev-blog

07. ์ถฉ๋Œ ํ•ด๊ฒฐ ๋ณธ๋ฌธ

๐Ÿ“š Language & CS knowledge/Git & GitHub

07. ์ถฉ๋Œ ํ•ด๊ฒฐ

Daehyunii 2022. 10. 8. 15:35

01. ํ•ฉ๋ณ‘์‹œ ๋ฐœ์ƒํ•˜๋Š” ์ถฉ๋Œ

  

  branch๋“ค์„ ๋ณ‘ํ•ฉํ•˜๋Š” ๊ณผ์ •์—์„œ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. main bracnh์™€ test branch ๊ฐ๊ฐ ๊ฐ™์€ ์œ„์น˜์˜ ๋‚ด์šฉ์„ ๋ถ€๋ถ„ ์ˆ˜์ •ํ•ด์„œ commit์„ ํ•˜๊ฒŒ ๋˜๋ฉด, git์˜ ์ž…์žฅ์—์„œ๋Š” ์–ด๋–ค๊ฒŒ ๋” ์ค‘์š”ํ•œ ๋‚ด์šฉ์ธ์ง€ ํ™•์ธํ•  ๋ฐฉ๋ฒ•์ด ์—†์œผ๋ฏ€๋กœ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ์ถฉ๋Œ ๋ฐœ์ƒ์‹œ ์ถฉ๋Œ์„ ํ•ด๊ฒฐํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค. VsCode๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๊ต‰์žฅํžˆ ์นœ์ ˆํ•˜๊ฒŒ ์„ค๋ช…ํ•ด์ฃผ๊ณ  ์žˆ๋‹ค. ์ถฉ๋Œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 

02. merge ๋ฐฉ์‹์—์„œ ๋ฐœ์ƒํ•œ ์ถฉ๋Œ

 

1. ์ถฉ๋Œ์„ ๋จผ์ € ํ•ด๊ฒฐํ•œ๋‹ค. ์•„๋ž˜์˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•˜๊ฒŒ ๋˜๋ฉด, vscode์—์„œ ์นœ์ ˆํ•˜๊ฒŒ ์–ด๋–ค ๋‚ด์šฉ์œผ๋กœ ํ•ฉ๋ณ‘์„ ํ•  ๊ฒƒ์ธ์ง€ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”์„ธ์ง€๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค. ๊ทธ๋ž˜์„œ ๊ฐœ๋ฐœ์ž๋Š” ๋‚ด์šฉ์„ ์„ ํƒํ•˜์—ฌ ์ถฉ๋Œ์„ ํ•ด๊ฒฐํ•œ๋‹ค.(Accept Current Change ๋“ฑ์˜ ์„ ํƒ๋ฒ„ํŠผ์„ ํ†ตํ•ด์„œ ์„ ํƒํ•˜๋ฉด ๋จ)

2. ์„ ํƒ์„ ํ•œ ํ›„์—๋Š” ๋‚ด์šฉ์ด ๋ณ€๊ฒฝ์ด ์ƒ๊ธฐ๊ฒŒ ๋˜๋Š” ๊ฒƒ์ด๋ฏ€๋กœ ์ƒˆ๋กญ๊ฒŒ git add . ๋ฅผ ํ•ด์ค€๋‹ค.

3. ๊ทธ๋ฆฌ๊ณ  ๋‹ค์‹œ git commit์„ ํ•œ๋‹ค.

4. :wq๋กœ ์ €์žฅํ•˜๊ณ  ์ข…๋ฃŒํ•˜๋ฉด ํ•ฉ๋ณ‘์ด ์™„๋ฃŒ๋œ๋‹ค.

5. ํ•ฉ๋ณ‘ ํ›„ ํ•ฉ์ณ์ง„ branch๋Š” ์‚ญ์ œํ•œ๋‹ค.

 

03. rebase ๋ฐฉ์‹์—์„œ ๋ฐœ์ƒํ•œ ์ถฉ๋Œ

 

  rebase์˜ ๋ฐฉ์‹์€ merge์™€ ๋‹ค๋ฅด๊ฒŒ commit๋“ค์ด ์ „๋ถ€ ์ด์–ด ๋ถ™์—ฌ์ง€๊ธฐ ๋•Œ๋ฌธ์— ์ถฉ๋Œ์ด commit ๋ณ„๋กœ ๊ณ„์†ํ•ด์„œ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. rebase์˜ ํŠน์„ฑ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์šฐ์„  ๊ธฐ๋ณธ์ ์ธ ์ถฉ๋Œ ํ•ด๊ฒฐ ๋ฐฉ์‹์€ merge์™€ ๋™์ผํ•˜๋‹ค. ํ•˜์ง€๋งŒ ์ค‘๊ฐ„์— ์ถ”๊ฐ€๋˜๋Š” ๊ณผ์ •๋“ค์ด ๋ช‡ ๊ฐ€์ง€ ๋” ์žˆ๋‹ค. ์ถฉ๋Œ ํ•ด๊ฒฐ๋ฐฉ์‹์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 

1. ์ถฉ๋Œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ๋‹ค.

2. git add . ๋ช…๋ น์–ด๋กœ ์ˆ˜์ •๋œ ๋‚ด์šฉ์„ git๊ด€๋ฆฌ์— ์ถ”๊ฐ€ํ•ด ์ค€๋‹ค.

3. <๋ช…๋ น์–ด>git rebase --continue ๋ช…๋ น์–ด๋กœ rebase ๋ณ‘ํ•ฉ์„ ๊ณ„์†ํ•œ๋‹ค. 

4. :wq๋กœ ์ €์žฅํ•˜๊ณ  ์ข…๋ฃŒํ•œ๋‹ค.

5. ์ด๋ ‡๊ฒŒ ๋ฐœ์ƒํ•˜๋Š” ๋ชจ๋“  ์ถฉ๋Œ๋ฌธ์ œ๋“ค์„ ์ด์–ด๋ถ™์—ฌ์งˆ commit๋“ค์˜ ์ถฉ๋Œ๋ฌธ์ œ๋“ค์ด ์ „๋ถ€ ํ•ด๊ฒฐ๋  ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•œ๋‹ค.

6. main์œผ๋กœ switchํ•œ๋‹ค.

7. git merge (์ด์–ด ๋ถ™์ธ branch ์ด๋ฆ„)์œผ๋กœ ๋’ค์ณ์ง„ main์„ ์•ž์œผ๋กœ ๋‹น๊ฒจ์ค€๋‹ค.

8. ํ•ฉ๋ณ‘ ํ›„ ํ•ฉ์ณ์ง„ branch๋Š” ์‚ญ์ œํ•œ๋‹ค.

 

* ์ฐธ๊ณ 

  ๋งŒ์•ฝ ํ•ฉ๋ณ‘ ์‹œ๋„ ํ›„์— ์ง€๊ธˆ ๋‹น์žฅ ์ถฉ๋Œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์–ด๋ ค์šด ๊ฒฝ์šฐ์—๋Š” ํ•ฉ๋ณ‘์„ ์ค‘๋‹จํ•˜๋ฉด ๋œ๋‹ค. ํ•ฉ๋ณ‘์„ ์ค‘๋‹จํ•˜๋Š” ๋ช…๋ น์–ด๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

<๋ช…๋ น์–ด>git merge --abort - merge ํ•ฉ๋ณ‘์„ ์ค‘๋‹จํ•œ๋‹ค.

<๋ช…๋ น์–ด>git rebase --abort - rebase ํ•ฉ๋ณ‘์„ ์ค‘๋‹จํ•œ๋‹ค.