[Git] conflict ๐Ÿ’ฅ

ยท

1 min read

[Git] conflict ๐Ÿ’ฅ

Photo by GR Stocks on Unsplash

์ฒ˜์Œ์œผ๋กœ team project๋Š” ์–ด๋–ป๊ฒŒ ๊ด€๋ฆฌ๋˜๋Š”์ง€ ๋ฐฐ์šธ ์ˆ˜ ์žˆ๋Š” ๋‚ ์ด์˜€๋‹ค. ๊ทธ ์ค‘์— conflict๋ž€ ๋ฌด์—‡์ด๊ณ  ์–ด๋–ป๊ฒŒ ํ•˜๋Š”์ง€ ์•Œ๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ ์žŠ์–ด๋ฒ„๋ฆฌ๊ณ  ์‹ถ์ง€ ์•Š์•„์„œ ๋ธ”๋กœ๊ทธ์— ์ž‘์„ฑํ•œ๋‹ค.

๊ฐœ๋…

  • branch์™€ branch์˜ merge๊ณผ์ •์—์„œ, ๋™์ผํ•œ ๋‚ด์šฉ์„ ๊ฐ์ž ๋‹ค๋ฅด๊ฒŒ ๋ณ€๊ฒฝํ•œ ์ด๋ ฅ์ด ์žˆ์„ ๋•Œ ๋ณ€๊ฒฝ ์ด๋ ฅ๋“ค๋ผ๋ฆฌ ๋ฐœ์ƒํ•˜๋Š” ์ถฉ๋Œ

๋ฐœ์ƒ๊ณผ์ •

  1. feature A๊ฐ€ ์ž‘์—… ์™„๋ฃŒ(Hello Dog) ๋’ค, github์œผ๋กœ git push origin feature/A -> pull request -> merge
  2. feature B๋„ ์ž‘์—… ์™„๋ฃŒ(Hello Cat) ๋’ค, github์œผ๋กœ git push origin feature/B -> pull request -> ๐Ÿ’ฅ conflict ๋ฐœ์ƒ!

  3. local์˜ master๋Š” ์•„์ง ์—…๋ฐ์ดํŠธ ๋˜์–ด์žˆ์ง€ ์•Š๋Š” ์ƒํ™ฉ์ด๋ผ github์— ์žˆ๋Š” master์™€ ๋งž์ถฐ ์ค€ ํ›„, conflict๋ฅผ ํ•ด๊ฒฐํ•ด์•ผํ•จ

  4. 3๋ฒˆ์„ ์œ„ํ•ด์„œ ๋กœ์ปฌ์—์„œ ์ž‘์—… branch๋ฅผ main์œผ๋กœ ๋ฐ”๊พผ ํ›„(git checkout main) main์„ local๋กœ pull ํ•˜๊ณ  (git pull origin main) ์šฐ๋ฆฌ๊ฐ€ ๋ณ€๊ฒฝํ•ด ์ฃผ๊ณ  ์‹ถ์€ feature B๋กœ ๋‹ค์‹œ branch๋ฅผ ๋ณ€๊ฒฝ(git checkout feature/B) ๊ทธ๋‹ค์Œ ๋งˆ์Šคํ„ฐ์— ์žˆ๋Š” ์ž‘์—… ๋‚ด์—ญ์„ B์—๊ฒŒ ํ•ฉ์ณ์•ผ ํ•จ(git merge main)

์ •๋ฆฌํ•˜๋ฉด
git checkout main
โฌ‡๏ธ
git pull origin main
โฌ‡๏ธ
git checkout feature/B
โฌ‡๏ธ
git merge main

  1. Conflict ํ•ด๊ฒฐ(์ฝ”๋“œ ์ˆ˜์ •)

  2. add -> commit -> push

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

<<< (current change)
=== (๊ตฌ๋ถ„์„ )
>>> (incoming change)
  • conflict๊ฐ€ ์žˆ๋Š” ๋ถ€๋ถ„์„ ์œ„์™€ ๊ฐ™์ด ํ‘œ์‹œํ•ด ์ฃผ๋Š”๋ฐ ์ € ํ‘œ์‹œ๋“ค์„ ๋‹ค ์ œ๊ฑฐํ•œ ๋’ค, ์›ํ•˜๋Š” ์ตœ์ข… ํ˜•ํƒœ๋กœ ๋งŒ๋“ค๊ณ  SAVE.

์ž๊พธ save๋ฅผ ๊นŒ๋จน๊ณ  git add commit push๋ฅผ ์ง„ํ–‰ํ•ด ์ฃผ์–ด ์•„๋ฌด๊ฒƒ๋„ ๋ณ€ํ•˜์ง€ ์•Š์•„ ํ˜ผ๋™์Šค๋Ÿฌ์› ๋‹ค. ์ €์žฅํ•˜๋Š”๊ฒƒ์„ ๊ผญ ๊ธฐ์–ตํ•˜์ž!

ย