5-4.conflict

ssnhhyejinยท2023๋…„ 2์›” 27์ผ
0

Git

๋ชฉ๋ก ๋ณด๊ธฐ
9/11
post-thumbnail

๐Ÿ’ฅBranch ์ถฉ๋Œ ํ•ด๊ฒฐ

๐ŸŽ‡๋ธŒ๋žœ์น˜ ๋ณ„ ๋ณ„๋„์˜ ํŒŒ์ผ ์ˆ˜์ • or ์ถ”๊ฐ€ ๐Ÿ‘‰ ์ถฉ๋ŒX
๐ŸŽ‡๊ฐ™์€ ํŒŒ์ผ์ด์ง€๋งŒ ๋‹ค๋ฅธ ํŒŒํŠธ๋ฅผ ์ˆ˜์ • ๐Ÿ‘‰ ์ถฉ๋ŒX

๐Ÿ”ฅ ๊ฐ™์€ ํŒŒ์ผ / ๊ฐ™์€ ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•  ๊ฒฝ์šฐ ์ถฉ๋Œ์ด ๋‚œ๋‹ค ๐Ÿ”ฅ


1) ๋ธŒ๋žœ์น˜ ๋ณ„ ํŒŒ์ผ ํ™•์ธ

๐Ÿ‘‰ main
ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main)
$ dir
f1.txt  f2.txt  f3.txt  s1.txt

๐Ÿ‘‰ test
ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (test)
$ dir
f1.txt  f2.txt  f3.txt  s1.txt  s2.txt

๐ŸŸํ˜„์žฌ s2.txt๊ฐ€ test์—๋งŒ ์žˆ๋Š”๊ฒƒ์„ ๋นผ๋ฉด branch๋ณ„ ํŒŒ์ผ์€ ๋ชจ๋‘ ๊ฐ™์Œ!


2) ๋ฐœ์ƒ

๐Ÿ“ main

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main)
$ vim s1.txt

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main)
$ cat s1.txt
  function a(){
  }
  function b(merge){
  }
  function c(){
  }

๐Ÿ“ test

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main)
$ git checkout test
Switched to branch 'test'

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (test)
$ vim s1.txt

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (test)
$ cat s1.txt
  function a(){
  }
  function b(conflict){
  }

๐Ÿฅž main์˜ s1.txt์™€ test์˜ s1.txt๋ฅผ ๊ฐ™์€ ํŒŒํŠธ์— ๋‹ค๋ฅธ ๋‚ด์šฉ์„ ์ ์Œ.
โžก function b(){ }: ํŒŒ๋ผ๋ฏธํ„ฐ ๋‹ด๋Š” ๋ถ€๋ถ„์„ ๋‹ค๋ฅด๊ฒŒ ์ ์Œ


๐Ÿ’ฅ merge - ์ถฉ๋Œ๋ฐœ์ƒ!

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main)
$ git merge test
Auto-merging s1.txt
CONFLICT (content): Merge conflict in s1.txt
Automatic merge failed; fix conflicts and then commit the result.
๐Ÿ‘‰ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•œ ํŒŒ์ผ ์ด๋ฆ„๊ณผ merge ์‹คํŒจ๋ฅผ ์•Œ๋ ค์คŒ

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main|MERGING)
$ git status
On branch main
Your branch is ahead of 'origin/main' by 5 commits.
  (use "git push" to publish your local commits)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:
        new file:   s2.txt

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   s1.txt

๐Ÿ” ํ˜„์žฌ merge๋Š” ์‹คํŒจํ•จ, ๊ทธ๋Ÿฌ๋‚˜ ๋ณ‘ํ•ฉ์„ ์‹œํ‚ฌ branch์˜ ์œ„์น˜์—์„œ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด s1.txt๋ฅผ ์ˆ˜์ •ํ•˜๋ผ๋Š” ์—๋Ÿฌ ๋ฉ”์„ธ์ง€๋ฅผ ํ™•์ธ


3) ํ•ด๊ฒฐ

๐ŸŒˆํ’€์ด

โœ…s1.txt ๋ฅผ ์—ด์–ด๋ณด๋ฉด git์—์„œ ์ปค๋ฐ‹์ง€์ , ์ถฉ๋Œ์ง€์ , ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์„ ํ‘œ์‹œํ•ด์คŒ

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main|MERGING)
$ cat s1.txt
  function a(){ 
  }
  <<<<<<< HEAD  	๐Ÿ‘‰ master์—์„œ ์ปค๋ฐ‹๋œ Head๋Š” function a()๋ถ€ํ„ฐ ๋ผ๋Š” ๋œป 
  function b(merge){
  }
  function c(){
  =======           ๐Ÿ‘‰ ์ด ๋ถ€๋ถ„์—์„œ ๊ฒน์นœ๋‹ค๋Š” ๋œป
  function b(conflict){
  >>>>>>> test		๐Ÿ‘‰  test ๋ธŒ๋žœ์น˜์—์„œ function b๋Š” ์ด๋ ‡๊ฒŒ ์“ฐ์—ฌ ์žˆ๋‹ค๋Š” ๋œป
  }

โžก conflict๊ฐ€ ์ผ์–ด๋‚˜๋Š” ๋ถ€๋ถ„์„ ์‚ฌ์šฉ์ž๊ฐ€ ์ˆ˜์ •ํ•˜๋ผ๊ณ  git์—์„œ ๊ถŒํ•œ์„ ๋„˜๊ฒจ์ฃผ๋Š” ๊ฒƒ.


๐ŸŒˆ์ˆ˜์ •

โœ…์‚ฌ์šฉ์ž๋Š” ์ถฉ๋Œ์ง€์ ์„ ํ™•์ธ ํ›„ ์ˆ˜์ •ํ•˜๊ณ  ๋‹ค์‹œ ์ €์žฅํ•˜๋ฉด ๋œ๋‹ค.

 function a() {
 }
 function b() {
 }
 function c(merge,conflict) {  ๐Ÿ‘‰ ์ˆ˜์ •
 }

๐ŸŒˆํ™•์ธ

๐Ÿฅž์ˆ˜์ • ํ›„ ์ปค๋ฐ‹

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main|MERGING)
$ git status
On branch main
Your branch is ahead of 'origin/main' by 5 commits.
 (use "git push" to publish your local commits)

You have unmerged paths.
 (fix conflicts and run "git commit")
 (use "git merge --abort" to abort the merge)

Changes to be committed:
       new file:   s2.txt

Unmerged paths: 						๐Ÿ‘‰ merge ์‹คํŒจํ•œ ๋ถ€๋ถ„์„ ์•Œ๋ ค์คŒ
 (use "git add <file>..." to mark resolution)
       both modified:   s1.txt  		๐Ÿ‘‰ ์ˆ˜์ • ์™„๋ฃŒํ•œ s1.txt๋ฅผ ๋ณด์—ฌ์คŒ


ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main|MERGING)
$ git add s1.txt   						๐Ÿ‘‰ s1.txt๋ฅผ add

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main|MERGING)
$ git status  							๐Ÿ‘‰ status์—์„œ ๋ฌธ์ œX
On branch main
Your branch is ahead of 'origin/main' by 5 commits.
 (use "git push" to publish your local commits)

All conflicts fixed but you are still merging.
 (use "git commit" to conclude merge)

Changes to be committed:
       modified:   s1.txt
       new file:   s2.txt


ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main|MERGING)
$ git commit -m "fix the conflict"		๐Ÿ‘‰์ปค๋ฐ‹โ€ผโ€ผ
[main f0bb4a7] fix the conflict

๐Ÿ•๋กœ๊ทธ ํ™•์ธ

ssnhh@DESKTOP-9APISNT MINGW64 ~/git/forGit (main)
$ git log --decorate --graph
*   commit f0bb4a72a9799720dae86aeb9144ab22e6b56278 (HEAD -> main)
|\  Merge: 8ab1175 d277107
| | Author: ssnhhyejin <ssnhhyejin@gmail.com>
| | Date:   Mon Feb 27 14:59:03 2023 +0900
| |
| |     fix the conflict
| |
| * commit d277107d28e7509df31e5651deb2db1d06282c67 (test)
| | Author: ssnhhyejin <ssnhhyejin@gmail.com>
| | Date:   Fri Feb 24 19:29:04 2023 +0900
| |
| |     modified-s1-funcb
| |
| * commit 039f491c26d6993230826492c27a7bf491835d50
| | Author: ssnhhyejin <ssnhhyejin@gmail.com>
| | Date:   Fri Feb 24 19:21:38 2023 +0900
| |
| |     stash finish
| |
| * commit e83248ce3e9fe5997a9c608f82b213d2b072d7e0
| | Author: ssnhhyejin <ssnhhyejin@gmail.com>
| | Date:   Fri Feb 24 15:30:59 2023 +0900
| |
| |     stash3
| |
| * commit cd27f5c0691a2ffb5a1e0e44f2abfd6e8c2273fd
| | Author: ssnhhyejin <ssnhhyejin@gmail.com>
| | Date:   Fri Feb 24 15:30:33 2023 +0900
| |
| |     stash2
| |
* | commit 8ab1175562963245e883a025af8541b727e5bb24
| | Author: ssnhhyejin <ssnhhyejin@gmail.com>
| | Date:   Fri Feb 24 19:30:00 2023 +0900
| |
| |     modify-s1-funcb
| |
* | commit 5904b3e818ffc15a18e334267efcf507c6a56ef8
|/  Author: ssnhhyejin <ssnhhyejin@gmail.com>
|   Date:   Fri Feb 24 19:26:21 2023 +0900
|
|       modified-s1
|
* commit 43bba6a4fe1bd2406e2f7376a6a618edd61b27c3
| Author: ssnhhyejin <ssnhhyejin@gmail.com>
| Date:   Fri Feb 24 14:52:04 2023 +0900
|
|     stash
|
*   commit ea7d7063b456a507337aec3cf6e816aa1b7ace5f (bran)
|\  Merge: 507d420 55c71f6
| | Author: ssnhhyejin <ssnhhyejin@gmail.com>

โžก๋กœ๊ทธ ํ™•์ธ: ์ •์ƒ์ ์œผ๋กœ merge ์™„๋ฃŒ๋จ

0๊ฐœ์˜ ๋Œ“๊ธ€

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด