Bibi's DevLog ๐Ÿค“๐ŸŽ

[์ง€์˜ฅ์—์„œ ์˜จ Git] 3. ๋ธŒ๋žœ์น˜ - ์›๋ฆฌ, branch, merge, checkout, fast-forward, Auto-merging&CONFLICT, stash, reset ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Git & GIthub ๊นƒ๊ณผ ๊นƒํ—ˆ๋ธŒ

[์ง€์˜ฅ์—์„œ ์˜จ Git] 3. ๋ธŒ๋žœ์น˜ - ์›๋ฆฌ, branch, merge, checkout, fast-forward, Auto-merging&CONFLICT, stash, reset

๋น„๋น„ bibi 2021. 2. 9. 00:13

3. ๊นƒ๊ณผ ๋ธŒ๋žœ์น˜

3.1 ๋ธŒ๋žœ์น˜๋ž€?

๋ธŒ๋žœ์น˜ branch
: ๋ฒ„์ „ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ์—์„œ, ์—ฌ๋Ÿฌ ๊ฐˆ๋ž˜๋กœ ํผ์ง€๋Š” ๋ฐ์ดํ„ฐ ํ๋ฆ„์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋ง.
(๋‚˜๋ญ‡๊ฐ€์ง€ - ๋‚˜๋ฌด๊ฐ€ ๊ฐ€์ง€์—์„œ ์ค„๊ธฐ๋ฅผ ๋ป—๋Š” ๋ชจ์–‘์ฒ˜๋Ÿผ.)

๋ธŒ๋žœ์น˜์˜ ๋™์ž‘์›๋ฆฌ

  • ๊นƒ์œผ๋กœ ๋ฒ„์ „๊ด€๋ฆฌ๋ฅผ ์‹œ์ž‘ํ•˜๋ฉด ๊ธฐ๋ณธ ๋ธŒ๋žœ์น˜์ธ main๋ธŒ๋žœ์น˜๊ฐ€ ๋งŒ๋“ค์–ด์ง„๋‹ค.
    • main๋ธŒ๋žœ์น˜ = (๊ตฌ) master๋ธŒ๋žœ์น˜.
  • HEAD๋Š” ํ˜„์žฌ ์ž‘์—…์ค‘์ธ ๋ธŒ๋žœ์น˜๋ฅผ ๋œปํ•œ๋‹ค.
    • HEAD -> master : ํ˜„์žฌ ์ž‘์—…์ค‘์ธ ๋ธŒ๋žœ์น˜๊ฐ€ master๋ธŒ๋žœ์น˜์ž„์„ ๋œปํ•จ
  • *๋ธŒ๋žœ์น˜๋Š” ์ปค๋ฐ‹์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐ์ด๋‹ค.
    ์‚ฌ์šฉ์ž๊ฐ€ ์ปค๋ฐ‹ํ•  ๋•Œ๋งˆ๋‹ค main๋ธŒ๋žœ์น˜๋Š” ์ตœ์‹  ์ปค๋ฐ‹์„ ๊ฐ€๋ฆฌํ‚จ๋‹ค. *

ํฌ์ธํ„ฐpointer : (ํ”„๋กœ๊ทธ๋ž˜๋ฐ) ๋‹ค๋ฅธ ๋ณ€์ˆ˜(์˜ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„ ์ฃผ์†Œ)๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋ณ€์ˆ˜๋ฅผ ๋œปํ•จ.

๊ฐ„์ ‘ ์ฐธ์กฐ - ๊ฐ’์„ ์ง์ ‘ ์“ฐ๋Š” ๊ฒŒ ์•„๋‹Œ ํŠน์ • ๋ฉ”๋ชจ๋ฆฌ๋ฒˆ์ง€์˜ ๊ฐ’์„ ์ฝ์–ด์„œ ์“ฐ๋„๋ก ํ•˜๋Š” ๊ฒƒ.

ํฌ์ธํ„ฐ๋Š” ์„œ๋กœ ๋‹ค๋ฅธ ํ•จ์ˆ˜ ๋‚ด์˜ ๋ณ€์ˆ˜๋ฅผ, ์ฃผ์†Œ๋ฅผ ํ†ตํ•ด ์ œ์–ดํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.

*๋ถ„๊ธฐ(branch) *
: main๋ธŒ๋žœ์น˜์—์„œ ๋ป—์–ด๋‚˜์˜ค๋Š” ์ƒˆ ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ.

  • ์ƒˆ ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค๋ฉด, ๊ธฐ์กด ํŒŒ์ผ ๋‚ด์šฉ์„ main๋ธŒ๋žœ์น˜์— ์œ ์ง€ํ•˜๋ฉด์„œ
    ๊ธฐ์กด ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ์ƒˆ๋กœ์šด ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

*๋ณ‘ํ•ฉ(merge, ๋จธ์ง€) *
: ๋ถ„๊ธฐํ–ˆ๋˜ ๋ธŒ๋žœ์น˜๋ฅผ main๋ธŒ๋žœ์น˜์— ํ•ฉ์น˜๋Š” ๊ฒƒ.

  • ์ƒˆ ๋ธŒ๋žœ์น˜์—์„œ ์›ํ•˜๋Š” ์ž‘์—…์„ ๋๋‚ธ ํ›„, ์ƒˆ ๋ธŒ๋žœ์น˜์˜ ํŒŒ์ผ์„ main๋ธŒ๋žœ์น˜์— ํ•ฉ์นœ๋‹ค.

3.2 ๋ธŒ๋žœ์น˜ ๋งŒ๋“ค๊ธฐ / ํ™•์ธํ•˜๊ธฐ (branch)

  • git branch
    : ๋ธŒ๋žœ์น˜๋ฅผ ํ™•์ธํ•˜๋Š” ๋ช…๋ น์–ด.
    • ํ˜„์žฌ ์‚ฌ์šฉ ์ค‘์ธ ๋ธŒ๋žœ์น˜์— *๊ฐ€ ํ‘œ์‹œ๋œ๋‹ค.
    • ์•„๋ฌด ๋ธŒ๋žœ์น˜๋„ ์ƒ์„ฑํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด master๋งŒ ์กฐํšŒ๋œ๋‹ค.
  • git branch ๋ธŒ๋žœ์น˜๋ช…
    : ํ˜„์žฌ ๋ธŒ๋žœ์น˜์—์„œ ํ•ด๋‹น ์ด๋ฆ„์„ ๊ฐ€์ง„ ๋ธŒ๋žœ์น˜๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ช…๋ น์–ด.
    • git branch apple : apple์ด๋ผ๋Š” ๋ธŒ๋žœ์น˜๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
    • ์ƒ์„ฑ ํ›„ git log : (HEAD -> master, apple)
      • master, apple : ๋ธŒ๋žœ์น˜๊ฐ€ master์™€ apple์ด ์žˆ๋‹ค.
      • HEAD -> master : ํ˜„์žฌ master๋ธŒ๋žœ์น˜์—์„œ ์ž‘์—… ์ค‘์ด๋‹ค.
rnala@DESKTOP-SL978IQ MINGW64 ~/manual (master)
$ git log
commit 80e828572041dac3ffbf45d66e8aa59c8639cfbe (HEAD -> master, ms, google, apple)
Author: Haina <bibi6666667@kakao.com>
Date:   Mon Feb 8 23:51:16 2021 +0900

    work3
  • master, ms, goolge, apple ๋ธŒ๋žœ์น˜๊ฐ€ work3์ปค๋ฐ‹ ์ƒํƒœ์—์„œ ๋งŒ๋“ค์–ด์กŒ๋‹ค.
    (master, ms, google, apple๋ธŒ๋žœ์น˜์—์„œ๋„ ์ตœ์‹  ์ปค๋ฐ‹์ด work3์ด๋‹ค)
rnala@DESKTOP-SL978IQ MINGW64 ~/manual (master)
$ git log --oneline
dffeb82 (HEAD -> master) master content 4
80e8285 (ms, google, apple) work3
9c6f763 work2
4353937 work1
  • HEAD -> master : ํ˜„์žฌ ๋ธŒ๋žœ์น˜๋Š” master์ด๋‹ค
  • dffeb82 (HEAD -> master) master content 4 : master๋ธŒ๋žœ์น˜์˜ ์ตœ์‹  ์ปค๋ฐ‹
  • 80e8285 (ms, google, apple) work3 : ms, google, apple๋ธŒ๋žœ์น˜์˜ ์ตœ์‹  ์ปค๋ฐ‹

๋ธŒ๋žœ์น˜ ์‚ฌ์ด ์ด๋™ํ•˜๊ธฐ (checkout)

์—ฌ๋Ÿฌ ๋ธŒ๋žœ์น˜ ์‚ฌ์ด๋ฅผ ์˜ค๊ฐ€๋ฉด์„œ ์ž‘์—…ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • git checkout ๋ธŒ๋žœ์น˜๋ช… : ํ˜„์žฌ ๋ธŒ๋žœ์น˜์—์„œ ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋กœ ์ด๋™.
    • apple๋ธŒ๋žœ์น˜๋กœ ์ด๋™ : git checkout apple = apple๋ธŒ๋žœ์น˜๋กœ ์ฒดํฌ์•„์›ƒ.
rnala@DESKTOP-SL978IQ MINGW64 ~/manual (apple)
$ git log --oneline
80e8285 (HEAD -> apple, ms, google) work3
9c6f763 work2
4353937 work1
  • (HEAD -> apple, ...)
    : ํ˜„์žฌ apple๋ธŒ๋žœ์น˜๋ฅผ ์‚ฌ์šฉ ์ค‘์ด๋‹ค.
  • apple๋ธŒ๋žœ์น˜ ๋ถ„๊ธฐ ์ „๊นŒ์ง€ master๋ธŒ๋žœ์น˜์— ์žˆ๋˜ ์ปค๋ฐ‹๋“ค์€ ๊ทธ๋Œ€๋กœ apple๋ธŒ๋žœ์น˜์— ๋ณต์‚ฌ๋˜์—ˆ๋‹ค.

3.3 ๋ธŒ๋žœ์น˜ ์ •๋ณด ํ™•์ธ

์—ฌ๋Ÿฌ ๋ธŒ๋žœ์น˜์—์„œ ๊ฐ๊ฐ ์ปค๋ฐ‹ํ•  ๋–„ ์–ด๋–ค ๊ด€๊ณ„๊ฐ€ ๋˜๋Š”์ง€ ํŒŒ์•…ํ•ด์•ผ ํ•œ๋‹ค.
๋˜, ๋ธŒ๋žœ์น˜ ์‚ฌ์ด์˜ ์ฐจ์ด์ ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

rnala@DESKTOP-SL978IQ MINGW64 ~/manual (apple)
$ git log --oneline
e55ae67 (HEAD -> apple) apple content 4
80e8285 (ms, google) work3
9c6f763 work2
4353937 work1
  • (HEAD -> apple) : ํ˜„์žฌ apple๋ธŒ๋žœ์น˜์— ์ฒดํฌ์•„์›ƒํ•œ ์ƒํƒœ์ด๋‹ค.
  • e55ae67 (HEAD -> apple) apple content 4 : apple๋ธŒ๋žœ์น˜์˜ ์ตœ์‹  ์ปค๋ฐ‹์€ ํ•ด์‹œ๊ฐ€ e55ae67์ธ ์ปค๋ฐ‹์ด๋‹ค.
rnala@DESKTOP-SL978IQ MINGW64 ~/manual (apple)
$ git log --oneline --branches
e55ae67 (HEAD -> apple) apple content 4
dffeb82 (master) master content 4
80e8285 (ms, google) work3
9c6f763 work2
4353937 work1

git log --oneline --branches : ๊ฐ ๋ธŒ๋žœ์น˜์˜ ์ปค๋ฐ‹์„ ํ•œ๊บผ๋ฒˆ์— ํ•œ ์ค„๋กœ ์กฐํšŒํ•จ.

  • e55ae67 (HEAD -> apple) apple content 4 : ํ˜„์žฌ apple๋ธŒ๋žœ์น˜ ์‚ฌ์šฉ ์ค‘์ด๋ฉฐ, ์ตœ์‹  ์ปค๋ฐ‹์€ e55ae67ํ•ด์‹œ์ธ ์ปค๋ฐ‹์ด๋‹ค
  • dffeb82 (master) master content 4 : master๋ธŒ๋žœ์น˜์˜ ์ตœ์‹  ์ปค๋ฐ‹์€ ํ•ด์‹œ๊ฐ€ dffeb82์ธ ์ปค๋ฐ‹์ด๋‹ค
  • 80e8285 (ms, google) work3 : ms๋ธŒ๋žœ์น˜์™€ google๋ธŒ๋žœ์น˜์˜ ์ตœ์‹  ์ปค๋ฐ‹์€ ํ•ด์‹œ๊ฐ€ 80e8285์ธ ์ปค๋ฐ‹์ด๋‹ค.
rnala@DESKTOP-SL978IQ MINGW64 ~/manual (apple)
$ git log --oneline --branches --graph
* e55ae67 (HEAD -> apple) apple content 4
| * dffeb82 (master) master content 4
|/
* 80e8285 (ms, google) work3
* 9c6f763 work2
* 4353937 work1

git log --oneline --branches --graph : ๋ชจ๋“  ๋ธŒ๋žœ์น˜์™€ ์ปค๋ฐ‹์˜ ๊ด€๊ณ„๋ฅผ ๊ทธ๋ž˜ํ”„ ํ˜•ํƒœ๋กœ ํ‘œ์‹œํ•จ

  • |์™€ /์ด ์ปค๋ฐ‹๊ณผ ์ปค๋ฐ‹์˜ ๊ด€๊ณ„๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค.
  • apple๋ธŒ๋žœ์น˜์—์„œ๋Š” work1, work2, work3 ๋‹ค์Œ์— apple content 4๊ฐ€ ๋งŒ๋“ค์–ด์กŒ๋‹ค.
  • master๋ธŒ๋žœ์น˜์—์„œ๋Š” work1, work2, work3 ๋‹ค์Œ์— master content 4๊ฐ€ ๋งŒ๋“ค์–ด์กŒ๋‹ค.
  • apple๋ธŒ๋žœ์น˜์™€ master๋ธŒ๋žœ์น˜๋Š” ๊ฐ™์€ ๋ถ€๋ชจ ์ปค๋ฐ‹(work3)์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.
    • apple๊ณผ master๋Š” work3 ์ปค๋ฐ‹๊นŒ์ง€๋Š” ๊ฐ™๊ณ , ๊ทธ ์ดํ›„ ๋ธŒ๋žœ์น˜๋งˆ๋‹ค ๋‹ค๋ฅธ ์ปค๋ฐ‹์„ ํ–ˆ๋‹ค.

๋ธŒ๋žœ์น˜ ์‚ฌ์ด์˜ ์ฐจ์ด์  ํ™•์ธ

rnala@DESKTOP-SL978IQ MINGW64 ~/manual (apple)
$ git log master..apple
commit e55ae678491ed0bf9d47e54738f351009c565ede (HEAD -> apple)
Author: Haina <bibi6666667@kakao.com>
Date:   Tue Feb 9 11:38:09 2021 +0900

    apple content 4

rnala@DESKTOP-SL978IQ MINGW64 ~/manual (apple)
$ git log apple..master
commit dffeb8201be8fb9e31efb4b0befafe40ce643659 (master)
Author: Haina <bibi6666667@kakao.com>
Date:   Tue Feb 9 11:09:30 2021 +0900

    master content 4

git log ๋ธŒ๋žœ์น˜1..๋ธŒ๋žœ์น˜2 : ๋ธŒ๋žœ์น˜1๊ธฐ์ค€์œผ๋กœ ๋ธŒ๋žœ์น˜2์™€ ๋น„๊ตํ•จ

  • git log master..apple : master๋ธŒ๋žœ์น˜ ๊ธฐ์ค€์œผ๋กœ apple๋ธŒ๋žœ์น˜์™€ ๋น„๊ตํ•จ
    • master๋ธŒ๋žœ์น˜์™€ ๋น„๊ตํ–ˆ์„ ๋•Œ apple๋ธŒ๋žœ์น˜์—๋งŒ ์žˆ๋Š” ์ปค๋ฐ‹ apple content 4 ์ถœ๋ ฅ๋จ
  • git log apple..master : apple๋ธŒ๋žœ์น˜ ๊ธฐ์ค€์œผ๋กœ master๋ธŒ๋žœ์น˜์™€ ๋น„๊ต
    • master๋ธŒ๋žœ์น˜์—๋งŒ ์žˆ๋Š” ์ปค๋ฐ‹ master content 4 ๊ฐ€ ์ถœ๋ ฅ๋จ

3.4 ๋ธŒ๋žœ์น˜ ๋ณ‘ํ•ฉํ•˜๊ธฐ (merge)

  • ๋ณ‘ํ•ฉ(merge)
    : ๋ธŒ๋žœ์น˜์—์„œ ์ž‘์—…์„ ๋๋‚ด๊ณ  ๊ธฐ์กด ๋ธŒ๋žœ์น˜์™€ ํ•ฉ์น˜๋Š” ๊ฒƒ.

  • ๋ธŒ๋žœ์น˜๋ฅผ ๋ณ‘ํ•ฉํ•˜๋ ค๋ฉด ๊ฐ€์žฅ ๋จผ์ € master๋ธŒ๋žœ์น˜๋กœ ์ฒดํฌ์•„์›ƒํ•ด์•ผ ํ•œ๋‹ค.

    git checkout master

์„œ๋กœ ๋‹ค๋ฅธ ํŒŒ์ผ ๋ณ‘ํ•ฉํ•˜๊ธฐ

  • git merge ๋ธŒ๋žœ์น˜๋ช… : ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋ฅผ ํ˜„์žฌ ๋ธŒ๋žœ์น˜์— ๋ณ‘ํ•ฉํ•œ๋‹ค.

  • merge์ˆ˜ํ–‰ ์‹œ ์ž๋™์œผ๋กœ ๋น”์ด ์ผœ์ง€๊ณ  ์ปค๋ฐ‹๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚œ๋‹ค.

    • ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜๋„ ์žˆ๊ณ , ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
  • git merge ๋ธŒ๋žœ์น˜๋ช… --no-edit : ๋น”์œผ๋กœ ์ปค๋ฐ‹๋ฉ”์‹œ์ง€๋ฅผ ํŽธ์ง‘ํ•˜์ง€ ์•Š๊ณ  ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ.

  • git merge ๋ธŒ๋žœ์น˜๋ช… --edit : ์œ„์˜ --no-edit์„ค์ •์„ ํ•ด์ œํ•˜๊ณ  ์‹ถ์„ ๋•Œ.

rnala@DESKTOP-SL978IQ MINGW64 ~/manual-2 (o2)
$ git log --oneline --branches --graph
* 804ba7b (HEAD -> o2) o2 work 2
| * da9f226 (master) master work 2
|/
* a85fbbe work 1
// ์ด ์ƒํƒœ์—์„œ..

rnala@DESKTOP-SL978IQ MINGW64 ~/manual-2 (master)
$ git log --oneline --branches --graph
*   c782675 (HEAD -> master) Merge branch 'o2' into master
|\
| * 804ba7b (o2) o2 work 2
* | da9f226 master work 2
|/
* a85fbbe work 1
  • o2๋ธŒ๋žœ์น˜์˜ o2 work 2์ปค๋ฐ‹์ด master๋ธŒ๋žœ์น˜์— ๋ณ‘ํ•ฉ๋˜๊ณ ,
    Merge branch 'o2' into master ์ปค๋ฐ‹์ด ์ƒˆ๋กœ ์ƒ๊ฒผ๋‹ค.

fast-forward merge ๋นจ๋ฆฌ๊ฐ๊ธฐ ๋ณ‘ํ•ฉ

  • master๋ธŒ๋žœ์น˜์—์„œ ๋ธŒ๋žœ์น˜๋ฅผ ๋ถ„๊ธฐํ•œ ๋’ค์—, master๋ธŒ๋žœ์น˜์— ์•„๋ฌด ๋ณ€ํ™”๊ฐ€ ์—†๋‹ค๋ฉด (์ƒˆ๋กœ์šด ์ปค๋ฐ‹์ด ์—†๋‹ค๋ฉด) : ๋ถ„๊ธฐํ•œ ๋ธŒ๋žœ์น˜์˜ ์ตœ์‹  ์ปค๋ฐ‹์„ master๋ธŒ๋žœ์น˜๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋„๋ก ํ•˜๋ฉด ๋์ด๋‹ค.
  • ์ด ๊ฒฝ์šฐ Fast-forward๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚˜๊ณ , ์ปค๋ฐ‹ ํ•ด์‰ฌ๊ฐ€ ์—…๋ฐ์ดํŠธ๋œ๋‹ค.
    • updating ์ปค๋ฐ‹ํ•ด์‰ฌ1..์ปค๋ฐ‹ํ•ด์‰ฌ2
      Fast-forward
  • ๋‹จ์ˆœํžˆ ํฌ์ธํ„ฐ๋งŒ ์›€์ง์ธ ๊ฒƒ์ด๋ฏ€๋กœ ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€ ์ฐฝ์€ ์—ด๋ฆฌ์ง€ ์•Š๋Š”๋‹ค.

๊ฐ™์€ ๋ฌธ์„œ์˜ ๋‹ค๋ฅธ ์œ„์น˜๋ฅผ ์ˆ˜์ •ํ–ˆ์„ ๋•Œ ๋ณ‘ํ•ฉํ•˜๊ธฐ (Auto-merging)

๋˜‘๊ฐ™์ด git checkout master, git merge ๋ธŒ๋žœ์น˜๋ช… ์œผ๋กœ ๋ณ‘ํ•ฉํ•œ๋‹ค.

$ git merge o2
Auto-merging work.txt
Merge made by the 'recursive' strategy.
 work.txt | 1 +
 1 file changed, 1 insertion(+)
  • Auto-merging ํŒŒ์ผ๋ช… : ๋ณ‘ํ•ฉ ์™„๋ฃŒ ๋ฉ”์‹œ์ง€.
    ๊ฐ™์€ ๋ฌธ์„œ์˜ ๋‹ค๋ฅธ ์œ„์น˜๋ฅผ ์ˆ˜์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— (๊ฒน์น˜๋Š” ์ˆ˜์ •์‚ฌํ•ญ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์—)
    ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ ์ž๋™์œผ๋กœ ํ•ฉ์ณ์ง„๋‹ค.

๊ฐ™์€ ๋ฌธ์„œ์˜ ๊ฐ™์€ ์œ„์น˜๋ฅผ ์ˆ˜์ •ํ–ˆ์„ ๋•Œ ๋ณ‘ํ•ฉํ•˜๊ธฐ (CONFLICT)

๊นƒ์€ ์ค„ ๋‹จ์œ„๋กœ ๋ณ€๊ฒฝ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ธฐ ๋•Œ๋ฌธ์—,
์„œ๋กœ ๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜๊ฐ€ ๊ฐ™์€ ํŒŒ์ผ์˜ ๊ฐ™์€ ์ค„์„ ์ˆ˜์ •ํ•œ ํ›„ ๋ณ‘ํ•ฉํ•˜๋ฉด ๋ธŒ๋žœ์น˜ ์ถฉ๋Œ(conflict)์ด ๋ฐœ์ƒํ•œ๋‹ค.

๋˜‘๊ฐ™์ด git checkout master, git merge ๋ธŒ๋žœ์น˜๋ช… ์œผ๋กœ ๋ณ‘ํ•ฉํ•œ๋‹ค.

rnala@DESKTOP-SL978IQ MINGW64 ~/manual-3/manual-4 (o2)
$ git checkout master
Switched to branch 'master'

rnala@DESKTOP-SL978IQ MINGW64 ~/manual-3/manual-4 (master)
$ git merge o2
Auto-merging work.txt
CONFLICT (content): Merge conflict in work.txt
Automatic merge failed; fix conflicts and then commit the result.

rnala@DESKTOP-SL978IQ MINGW64 ~/manual-3/manual-4 (master|MERGING)
$
  • CONFLICT (content): Merge conflict in work.txt Automatic merge failed; fix conflicts and then commit the result.
    : work.txt๋ฅผ ์ž๋™ ๋ณ‘ํ•ฉํ•˜๋Š” ๋™์•ˆ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ–ˆ์Œ์„ ์˜๋ฏธํ•จ.
    ์ถฉ๋Œ์ด ์ƒ๊ธด ๋ฌธ์„œ๋Š” ์ž๋™์œผ๋กœ ๋ณ‘ํ•ฉ๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ(Automatic merge failed;)
    ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์ถฉ๋Œ ๋ถ€๋ถ„์„ ํ•ด๊ฒฐํ•œ ํ›„ ์ปค๋ฐ‹ํ•ด์•ผ ํ•จ.
  1. ๋น”์—์„œ ํ•ด๋‹น ๋ฌธ์„œ๋ฅผ ์—ด์–ด ์ง์ ‘ ์ˆ˜์ •ํ•œ๋‹ค.
    ๋ฌธ์„œ์—๋Š” ์ถฉ๋Œ์ด ์ผ์–ด๋‚œ ๋‘ ๋ธŒ๋žœ์น˜์˜ ๋‚ด์šฉ์ด ํ•œ๊บผ๋ฒˆ์— ๋‚˜ํƒ€๋‚˜ ์žˆ๋‹ค.
# title
content
<<<<<<< HEAD
master content 2
=======
o2 content 2
>>>>>>> o2
# title
content
  • <<<<<<< HEAD
    master content 2
    =======
    : ํ˜„์žฌ ๋ธŒ๋žœ์น˜์—์„œ ์ˆ˜์ •ํ•œ ๋‚ด์šฉ.
  • =======
    o2 content 2
    >>>>>>> o2
    : o2๋ธŒ๋žœ์น˜์—์„œ ์ˆ˜์ •ํ•œ ๋‚ด์šฉ.
  1. ๋‚ด์šฉ์„ ์›ํ•˜๋Š” ๋Œ€๋กœ ์ˆ˜์ •ํ•œ ํ›„, <<<<<<< HEAD, =======, >>>>>>> o2 ๋ฅผ ์‚ญ์ œํ•˜๊ณ  ๋ฌธ์„œ๋ฅผ ์ €์žฅํ•œ๋‹ค.

  2. ์ˆ˜์ •ํ•œ ๋ฌธ์„œ๋ฅผ add, commitํ•œ๋‹ค.

๋จธ์ง€ ๋ฐ ์ถฉ๋Œ ํ•ด๊ฒฐ ํ”„๋กœ๊ทธ๋žจ
: ๋จธ์ง€์™€ ์ถฉ๋Œ์„ ์ž๋™์œผ๋กœ ํ•ด๊ฒฐํ•ด ์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ๋“ค.

๋ณ‘ํ•ฉ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ค‘ 2way merge / 3way merge(๊ถŒ์žฅ)๋ฅผ ์ง€์›ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์‚ฌ์šฉํ•œ๋‹ค.

P4Merge, Meld, Kdiff3, Araxis Merge ๋“ฑ.

๋ณ‘ํ•ฉ์ด ๋๋‚œ ๋ธŒ๋žœ์น˜ ์‚ญ์ œํ•˜๊ธฐ

๋ณ‘ํ•ฉ ํ›„ ๋” ์ด์ƒ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ๋ธŒ๋žœ์น˜๋Š” ์‚ญ์ œํ•œ๋‹ค.
*๋‹จ, ๋ธŒ๋žœ์น˜๋ฅผ ์‚ญ์ œํ•˜๋”๋ผ๋„ ๊ฐ™์€ ์ด๋ฆ„์˜ ๋ธŒ๋žœ์น˜๋ฅผ ๋‹ค์‹œ ๋งŒ๋“ค๋ฉด ์˜ˆ์ „ ๋‚ด์šฉ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
์‚ฌ์‹ค์ƒ ์‚ญ์ œ๊ฐ€ ์•„๋‹Œ, ๊นƒ์˜ ํ๋ฆ„์—์„œ ๊ฐ์ถ”๋Š” ๊ฒƒ ๋ฟ์ด๋‹ค.

  • git checkout master : ๋ธŒ๋žœ์น˜ ์‚ญ์ œ๋ฅผ ํ•  ๋•Œ๋„ ๊ฐ€์žฅ ๋จผ์ € master๋ธŒ๋žœ์น˜๋กœ ์ฒดํฌ์•„์›ƒํ•ด์•ผ ํ•œ๋‹ค.
  • git branch -d ๋ธŒ๋žœ์น˜๋ช… : ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋ฅผ ์‚ญ์ œํ•œ๋‹ค.
  • git branch -D ๋ธŒ๋žœ์น˜๋ช… : ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋ฅผ ์‚ญ์ œํ•œ๋‹ค. ํ•ด๋‹น ๋ธŒ๋žœ์น˜๊ฐ€ master์— ๋ณ‘ํ•ฉ๋˜์ง€ ์•Š์•˜๋‹ค๊ณ  ํ•ด๋„ ์‚ญ์ œํ•œ๋‹ค.
  • ๊ฒฐ๊ณผ ๋ฉ”์‹œ์ง€ : Deleted branch o2 (was ์ปค๋ฐ‹ํ•ด์‹œ)

3.5 ๋ธŒ๋žœ์น˜ ๊ด€๋ฆฌํ•˜๊ธฐ

๊นƒ๊ณผ ๋ธŒ๋žœ์น˜๋ฅผ ํŽธํ•˜๊ฒŒ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๋ช…๋ น๋“ค.

๋ธŒ๋žœ์น˜์—์„œ checkout์™€ reset์˜ ์ž‘๋™ ์›๋ฆฌ

๋ธŒ๋žœ์น˜๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐœ์ผ ๋•Œ checkout ์‚ฌ์šฉํ•˜๊ธฐ -HEAD ์ œ์–ด

  • git checkout์€ HEAD๋ฅผ ์ œ์–ดํ•ด ๋ธŒ๋žœ์น˜๋ฅผ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • HEAD๋Š” ํ˜„์žฌ ์ž‘์—… ํŠธ๋ฆฌ๊ฐ€ ์–ด๋–ค ๋ฒ„์ „์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž‘์—… ์ค‘์ธ์ง€ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐ์ด๋‹ค.

    • HEAD๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋งˆ์Šคํ„ฐ ๋ธŒ๋žœ์น˜๋ฅผ ๊ฐ€๋ฆฌํ‚จ๋‹ค.
    • ๋ธŒ๋žœ์น˜๋ฅผ ๋ณ€๊ฒฝํ•  ๋•Œ ์‚ฌ์šฉํ–ˆ๋˜ git checkout ๋ช…๋ น์–ด๋Š” ๊ณง,
      HEAD๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š” ๊ฒƒ์„ ์ œ์–ดํ•˜๋Š” ๋ช…๋ น์–ด์ด๋‹ค.
      git checkout sub์ฒ˜๋Ÿผ ๋ธŒ๋žœ์น˜๋ฅผ sub๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด, HEAD๋Š” sub๋ฅผ ๊ฐ€๋ฆฌํ‚จ๋‹ค.
  • ๊ฐ ๋ธŒ๋žœ์น˜๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ, ๋ธŒ๋žœ์น˜์˜ ์ปค๋ฐ‹ ์ค‘ ๊ฐ€์žฅ ์ตœ์‹ ์˜ ์ปค๋ฐ‹์„ ๊ฐ€๋ฆฌํ‚จ๋‹ค.

    • ์ƒˆ๋กœ ์ƒ์„ฑ๋œ ๋ธŒ๋žœ์น˜ ์—ญ์‹œ ๋ณต์‚ฌ๋œ ์ปค๋ฐ‹๋“ค ์ค‘ ๊ฐ€์žฅ ์ตœ์‹ ์˜ ์ปค๋ฐ‹์„ ๊ฐ€๋ฆฌํ‚จ๋‹ค.

๋ธŒ๋žœ์น˜๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐœ์ผ ๋–„ reset์‚ฌ์šฉํ•˜๊ธฐ

  • git reset์€ HEAD๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋ธŒ๋žœ์น˜์˜ ์ตœ์‹  ์ปค๋ฐ‹์„ ์›ํ•˜๋Š” ์ปค๋ฐ‹์œผ๋กœ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ํ˜„์žฌ ๋ธŒ๋žœ์น˜๊ฐ€ ์•„๋‹Œ ์–ด๋–ค ๋ธŒ๋žœ์น˜์— ์žˆ๋Š” ์ปค๋ฐ‹์ด๋“  ๊ณจ๋ผ์„œ ์ตœ์‹  ์ปค๋ฐ‹์œผ๋กœ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
    git reset ์ปค๋ฐ‹ํ•ด์‹œ (๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜์˜ ์ปค๋ฐ‹ํ•ด์‹œ๋ฅผ ๋„ฃ๋Š”๋‹ค)

  • ๊ฒฐ๊ณผ ๋ฉ”์‹œ์ง€ : Unstaged changes after reset: ํŒŒ์ผ๋ช…

  • ๋ธŒ๋žœ์น˜์™€์˜ ์—ฐ๊ฒฐ์ด ๋Š๊ธด ์ปค๋ฐ‹์€ ์‚ญ์ œ๋œ๋‹ค.

์ˆ˜์ • ์ค‘์ธ ํŒŒ์ผ ๊ฐ์ถ”๊ธฐ ๋ฐ ๋˜๋Œ๋ฆฌ๊ธฐ

stash
: ์ž‘์—… ํŠธ๋ฆฌ์—์„œ ํŒŒ์ผ ์ˆ˜์ • ํ›„, ์•„์ง ์ปค๋ฐ‹ํ•˜์ง€ ์•Š์€ ์ƒํƒœ์—์„œ ๋‹ค๋ฅธ ํŒŒ์ผ์„ ์ปค๋ฐ‹ํ•ด์•ผ ํ•  ๋•Œ
์•„์ง ์ปค๋ฐ‹ํ•˜์ง€ ์•Š์€ ํŒŒ์ผ์„ ์ž ์‹œ ๊ฐ์ถฐ๋‘๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

  • git stash (๋˜๋Š” git stash save)
    : ์ปค๋ฐ‹ํ•˜์ง€ ์•Š์€ ์ž‘์—…ํŠธ๋ฆฌ์˜ ์ˆ˜์ • ๋‚ด์šฉ์„ ์ž ์‹œ ๋ณด๊ด€ํ•˜๋Š” (๊ฐ์ถฐ๋‘๋Š”) ๋ช…๋ น์–ด.

    • ํŒŒ์ผ๋“ค์ด ์‚ฌ๋ผ์ง€๋Š” ๊ฒƒ์ด ์•„๋‹Œ ์ž ์‹œ ๊ฐ์ถฐ๋‘๋Š” ๊ฒƒ์ผ ๋ฟ์ด๋‹ค.
    • ๊ฒฐ๊ณผ ๋ฉ”์‹œ์ง€ : Saved working directory and index state WIP on ๋ธŒ๋žœ์น˜๋ช…: ์ปค๋ฐ‹ํ•ด์‹œ ํŒŒ์ผ๋ช…
    • git stash ์ดํ›„ git status๋กœ ์กฐํšŒํ•˜๋ฉด, ์ปค๋ฐ‹ํ•  ๊ฒƒ์ด ์—†๋‹ค๊ณ  ๋‚˜์˜จ๋‹ค.
      (nothing to commit, working tree clean)
  • git stash list
    : stash๋œ ํŒŒ์ผ๋“ค์˜ ๋ชฉ๋ก์„ ํ™•์ธํ•˜๋Š” ๋ช…๋ น์–ด.
    stash list๋Š” ์Šคํƒ ๋ฐฉ์‹์œผ๋กœ ์ €์žฅ๋˜์–ด stash stack์ด๋ผ๊ณ ๋„ ํ•œ๋‹ค.

    • stash@{0} ์— ํ•ญ์ƒ ๊ฐ€์žฅ ์ตœ๊ทผ์— ์ถ”๊ฐ€๋œ ํŒŒ์ผ์ด ๋‹ด๊ธด๋‹ค.
    • ์ƒˆ๋กœ์šด ํ•ญ๋ชฉ์ด ์ถ”๊ฐ€๋˜๋ฉด ๊ธฐ์กด ํŒŒ์ผ์€ stash@{1}๋กœ ๋ฐ€๋ ค๋‚˜๊ณ , ์ƒˆ ํŒŒ์ผ์ด stash@{0}์ด ๋œ๋‹ค.

๊ธ‰ํ•œ ์ž‘์—…์„ ๋งˆ์น˜๊ณ , stashํ•ด๋‘” ํŒŒ์ผ์„ ๋‹ค์‹œ ๊บผ๋‚ด์„œ ์ž‘์—…ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • git stash pop
    : stash list์—์„œ ๊ฐ€์žฅ ์ตœ๊ทผ ํ•ญ๋ชฉ (stash@{0})์„ ๋˜๋Œ๋ฆฐ๋‹ค. (stash ์ด์ „ ์ƒํƒœ๋กœ)
  • git stash apply
    : stash list์—์„œ ๊ฐ€์žฅ ์ตœ๊ทผ ํ•ญ๋ชฉ์„ ๋˜๋Œ๋ฆฌ์ง€๋งŒ, ์ €์žฅ ๋‚ด์—ญ์„ ๊ทธ๋Œ€๋กœ ๋‚จ๊ฒจ๋‘”๋‹ค.
    • stash list์˜ ์ˆ˜์ •๋‚ด์šฉ์„ ๋‚˜์ค‘์— ๋˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„ ๋•Œ ํ™œ์šฉํ•จ.
  • git stash drop
    : stash list์—์„œ ๊ฐ€์žฅ ์ตœ๊ทผ ํ•ญ๋ชฉ์„ ์‚ญ์ œํ•œ๋‹ค.