ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

git

4. git branch ๋ณ‘ํ•ฉํ•˜๊ธฐ (merge)

๋Œ•๋Œ•์ด๋ฐœ๐Ÿพ 2018. 4. 5. 01:14


์ฝ”๋“œ์˜ ์ด๋ ฅ์„ ์ €์žฅํ•˜๋Š” commit๊ณผ ์—ญํ• ์„ ๋ถ„๋ฆฌ์‹œ์ผœ์ฃผ๋Š” branch๊นŒ์ง€ ๋‹ค๋ค„๋ดค์œผ๋‹ˆ ์ค‘์š”ํ•œ ๊ธฐ๋Šฅ์ค‘ ํ•˜๋‚˜์ธ merge๋ฅผ ๋‹ค๋ค„๋ณด๋ คํ•œ๋‹ค.

๋ฌผ๋ก  add , commit , branch , merge ๋Š” ๋นˆ๋„์ˆ˜๊ฐ€ ๋งŽ์€ ๋ช…๋ น์–ด๋“ค์ด๋‹ˆ ์–ด๋Šํ•˜๋‚˜ ์•ˆ์ค‘์š”ํ•œ๊ฑด ์—†๋Š” ๊ฒƒ ๊ฐ™๋‹ค.


commandgoogle results%
commit528,0007.981980075
push523,0007.906393143
pull506,0007.649397572
clone489,0007.392402002
checkout470,0007.105171658
add446,0006.742354382
branch439,0006.636532676
log388,0005.865545964
diff369,0005.578315621
fetch355,0005.36667221
merge354,0005.351554823
init343,0005.185263572
status286,0004.323572541
reset267,0004.036342197
tag246,0003.718877081
rebase203,0003.068829461
rm142,0002.146668884
show104,0001.572208197
bisect62,8000.9493718726
grep49,4000.7467988934
mv44,7000.6757471768

์ถœ์ฒ˜ : ์ƒํ™œ์ฝ”๋”ฉ https://opentutorials.org/course/2708/15211


๋ช…๋ น์–ด ์‚ฌ์šฉ ๋นˆ๋„์ˆ˜๋ฅผ ๋ณด๋ฉด ๋ฌผ๋ก  1,2,3 ๋“ฑ๊นŒ์ง€๋Š” ์•„๋‹ˆ์ง€๋งŒ ๋งค์šฐ ์ƒ์œ„๊ถŒ์— ์†ํ•ด์žˆ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์•„๋งˆ๋„ ๋นˆ๋„์ˆ˜๊ฐ€ 4ํ”„๋กœ ์ด์ƒ ๋˜๋Š” ๋ช…๋ น์–ด๋“ค์€ ๋‚˜๋„ ๋งŽ์ด ์“ด ๊ฒƒ ๊ฐ™๋‹ค.


merge๋ผ๋Š” ๋ช…๋ น์–ด๋Š” ์ œ๋ชฉ์—์„œ๋„ ๋งํ–ˆ๋“ฏ์ด ๊ฐ ๋ธŒ๋Ÿฐ์น˜์˜ ์ตœ๊ทผ ์ปค๋ฐ‹์„ ์„œ๋กœ ๋ณ‘ํ•ฉํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. ์—ฌ๊ธฐ์„œ ์กฐ์‹ฌํ•ด์•ผํ•  ๊ฒƒ์€ ํ˜„์žฌ ์–ด๋Šbranch์— checkout๋˜์–ด์žˆ๋Š”์ง€ ์ž˜ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค. 



ํ˜„์žฌ checkout ๋˜์–ด์žˆ๋Š” ๋ธŒ๋Ÿฐ์น˜๋ฅผ A๋ผํ•˜๊ณ  B๋Š” ๋˜๋‹ค๋ฅธ ๋ธŒ๋Ÿฐ์น˜๋ผ๊ณ  ๊ฐ€์ •ํ•˜์ž.


A๋ผ๋Š” ๋ธŒ๋Ÿฐ์น˜์—์„œ A1์ด๋ผ๋Š” commit์„ ๊ฐ€์ง€๊ณ ์žˆ๊ณ , B๋ผ๋Š” ๋ธŒ๋Ÿฐ์น˜์—๋Š” B1๊ณผ B2๋ผ๋Š” commit์„ ๊ฐ€์ง€๊ณ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์ž.


๊ทธ๋Ÿผ ๋‚ด๊ฐ€ ๋งŒ์•ฝ $git merge B    ๋ผ๋Š” ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ฒŒ ๋˜๋ฉด 


ํ˜„์žฌ ๋‚ด๊ฐ€ checkout ๋˜์–ด์žˆ๋Š” ๋ธŒ๋Ÿฐ์น˜ A์˜ A1 commit์— ๋ธŒ๋Ÿฐ์น˜ B์˜ B2 commit์„ ๋ณ‘ํ•ฉ ์‹œํ‚ค๋Š” ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ๋œ๋‹ค.


์ฆ‰, A2์˜ commit์ด ๊ฐ€์žฅ ๋งŽ์€ ์†Œ์Šค์ฝ”๋“œ๋ฅผ ํฌํ•จํ•˜๊ณ ์žˆ๋Š” commit์ด ๋œ๋‹ค๋Š” ์–˜๊ธฐ์ด๋‹ค. ๋ณดํ†ต A2์ฒ˜๋Ÿผ commit์ด๋ฆ„์ด ์ง€์–ด์ง€์ง€ ์•Š๊ณ 

merge~~~~ ์ด๋Ÿฐ์‹์˜ ๋„ค์ž„์ด ๋ถ™๊ธดํ•œ๋‹ค. 


----------------------------------------------------------------------------------------------------------------------


merge๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ณด์ž๋ฉด ์ด์ •๋„๋กœ๋งŒ ๋ด๋„๋˜๋Š”๋ฐ ์‚ฌ์‹ค merge ํ•  ๋•Œ ์ถฉ๋Œ์ด ๊ต‰์žฅํžˆ ๋งŽ์ด ๋ฐœ์ƒํ•œ๋‹ค. ๊ทธ ์ด์œ ๋Š” ๋„ˆ๋ฌด๋‚˜๋„ ๋‹ค์–‘ํ•˜๊ธฐ๋•Œ๋ฌธ์— ์ด์œ ๋ฅผ ๋”ฑ ์ง‘๊ธฐ๊ฐ€ ์–ด๋ ค์šธ ๊ฒƒ๊ฐ™๋‹ค. ์„œ๋กœ ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์ด ๋„ˆ๋ฌด๋งŽ์ด ์ˆ˜์ •๋๊ฑฐ๋‚˜, ๊ฐ์ž๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜๋Š” ํŒŒ์ผ์˜ ๋‚ด์šฉ์ด ๋‹ค๋ฅด๊ฑฐ๋‚˜ ๋“ฑ๋“ฑ.. 
gitignore์ด๋ผ๋Š” ์„ค์ •ํŒŒ์ผ์„ ํŽธ์ง‘ํ•ด์ค˜์•ผ ํ•˜๋Š”๋ฐ ํ”„๋กœ์ ํŠธ์˜ ํŠน์„ฑ์ด๋‚˜ ์šด์˜์ฒด์ œ ๋“ฑ๋“ฑ ๊ฐ์ž์˜ ์ปดํ“จํ„ฐ๊ฐ€ ๊ฐ€์ง„ ํ™˜๊ฒฝ์ด ๋‹ค๋ฅผ ์ˆ˜๊ฐ€ ์žˆ๊ธฐ๋•Œ๋ฌธ์— ์ž๊ธฐ ํ”„๋กœ์ ํŠธ์— ๋งž๊ฒŒ ํŒ€์› ๋ชจ๋‘๊ฐ€ ๋™์ผํ•˜๊ฒŒ ์ˆ˜์ •ํ•ด์ค˜์•ผ ํ•œ๋‹ค. (์ด๊ฑด ๊ตฌ๊ธ€๋ง์„..)


๋‚˜๊ฐ™์€๊ฒฝ์šฐ๋Š” ๊ฐ™์ด ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋Š” ํŒ€์›๋ถ„์˜ ์ฝ”๋“œ์™€ ๋ณ‘ํ•ฉํ•˜๋Š” ์ž‘์—…์„ ํ•  ๋•Œ merge ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ๊ต‰์žฅํžˆ ํŽธ๋ฆฌํ•˜๋ฉด์„œ๋„ ๋•Œ๋กœ๋Š” ๋„ˆ๋ฌด ๊ณ ์ƒ์‹œํ‚ค๋Š” ๋ช…๋ น์–ด ์ค‘์— ํ•˜๋‚˜์ด๋‹ค.(์ถฉ๋Œ์ด ํ•œ๋ฒˆ ๋‚˜๊ธฐ ์‹œ์ž‘ํ•˜๋ฉด ๋๋„์—†๋Š”..)

๋ณธ์ธ ์Šค์Šค๋กœ์˜ ์ฝ”๋“œ์ž‘์—…์ด ์ „๋ถ€๋ผ๋ฉด ๋กœ์ปฌ ๋ธŒ๋Ÿฐ์น˜๋“ค๋ผ๋ฆฌ ๋ฐ”๋กœ merge๋ฅผ ํ•ด์ฃผ๋ฉด ๋˜๊ฒ ์ง€๋งŒ github๋ฅผ ํ†ตํ•œ ํŒ€์›๊ฐ„์˜ ์ฝ”๋“œ๋ณ‘ํ•ฉ ์ž‘์—…์„ ํ•œ๋‹ค๋ฉด ์›๊ฒฉ์ €์žฅ์†Œ๋ฅผ ์ œ์–ดํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ผ๋‹จ ์•Œ์•„์•ผํ•œ๋‹ค. 
๋‹ค์Œ ํฌ์ŠคํŒ…์€ ๋กœ์ปฌ์ด ์•„๋‹Œ ์›๊ฒฉ์ €์žฅ์†Œ๋ฅผ ๋‹ค๋ฃจ๋Š” ๋ฐฉ๋ฒ•์„ ๊ฐ„๋‹จํžˆ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ๋‹ค!



๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
๊ธ€ ๋ณด๊ด€ํ•จ