이제까지는 우리가 서로 다른 파일 또는 같은 파일이라도 다른 부분을 서로 다른 브랜치들이 수정을 했기 때문에 그것들을 merger하거나 rebase할 때 별 문제가 발생하지 않았다
그런데 만약 이쪽 브랜치와 저쪽 브랜치에서 같은 파일에 같은 줄에 서로 다른 내용을 입력해 버리면 이것들을 병합할 때 컴퓨터는 그 둘 중에 어떤 걸 채택해야 될지 모르기 때문에 충돌 발생
그래서 "나 이거 어떻게 병합해야 될지 모른니까 네가 해결하고 알려줘"
이렇게 프로그래머한테 건네게 된다
그 상황을 한번 만들어 보자
브랜치 간 충돌
- 파일의 같은 위치에 다른 내용이 입력된 상황
1. merge 충돌 해결하기
git merge conflict-1로 병합을 시도하면 충돌 발생
- 오류 메시지와 git status 확인
$ git merge conflict-1
Auto-merging tigers.yaml
CONFLICT (content): Merge conflict in tigers.yaml
Automatic merge failed; fix conflicts and then commit the result.
$ git status
On branch main
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: tigers.yaml
no changes added to commit (use "git add" and/or "git commit -a")

Accept Current Change 클릭하면

당장 충돌 해결이 어려울 경우 아래 명령어로 merge 중단
git merge --abort

해결 가능 시
- 충돌 부분을 수정한 뒤 git add .

main과 conflict1이 합쳐짐

2. rebase 충돌 해결
merge는 양쪽의 갈래를 한 번에 이어붙이는 것이기에 충돌 해결이 commit 한 번에 끝남
rebase는 branch 안에 있는 모든 커밋마다 충돌과정을 따로따로 차례로 해결해주어야 함
conflict-2에서 git rebase main로 리베이스 시도하면 충돌 발생
- 오류 메시지와 git status 확인
$ git rebase main
Auto-merging leopards.yaml
CONFLICT (content): Merge conflict in leopards.yaml
error: could not apply 5c8fd8d... Edit Leopards
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase
--abort".
Could not apply 5c8fd8d... Edit Leopards
$ git status
interactive rebase in progress; onto db35937
Last command done (1 command done):
pick 5c8fd8d Edit Leopards
Next command to do (1 remaining command):
pick a469a7c Edit Panthers
(use "git rebase --edit-todo" to view and edit)
You are currently rebasing branch 'conflict-2' on 'db35937'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: leopards.yaml
no changes added to commit (use "git add" and/or "git commit -a")
- both modified : 양쪽 파일에서 이 파일을 건드리려 한다. 개발자 당신이 해결해 달라
Accept Incoming Change 선택


당장 충돌 해결이 어려울 경우 아래 명령어로 rebase 중단
git rebase --abort
해결 가능 시
- 충돌 부분을 수정한 뒤 git add .
- 아래 명령어로 계속
git rebase --continue
마지막에 :wq로 commit


- 충돌이 모두 해결될 때까지 반복
main에서 git merge conflict-2로 마무리
conflict-1, conflict-2 삭제
'Git, Github 😺 > 제대로 파는 Git & GitHub - by 얄코' 카테고리의 다른 글
[Git, GitHub] GitHub에서 프로젝트 다운받기 (0) | 2024.01.20 |
---|---|
[Git, GitHub] GitHub와 작업 중인 프로젝트 연동 (GitHub와 IntelliJ 연동하기) (0) | 2024.01.20 |
[제대로 파는 Git & Github # 16] GitHub은 뭐고 왜 쓰나요? (0) | 2024.01.20 |
[제대로 파는 Git & Github # 15] SourceTree로 진행해보기 (0) | 2024.01.20 |
이제까지는 우리가 서로 다른 파일 또는 같은 파일이라도 다른 부분을 서로 다른 브랜치들이 수정을 했기 때문에 그것들을 merger하거나 rebase할 때 별 문제가 발생하지 않았다
그런데 만약 이쪽 브랜치와 저쪽 브랜치에서 같은 파일에 같은 줄에 서로 다른 내용을 입력해 버리면 이것들을 병합할 때 컴퓨터는 그 둘 중에 어떤 걸 채택해야 될지 모르기 때문에 충돌 발생
그래서 "나 이거 어떻게 병합해야 될지 모른니까 네가 해결하고 알려줘"
이렇게 프로그래머한테 건네게 된다
그 상황을 한번 만들어 보자
브랜치 간 충돌
- 파일의 같은 위치에 다른 내용이 입력된 상황
1. merge 충돌 해결하기
git merge conflict-1로 병합을 시도하면 충돌 발생
- 오류 메시지와 git status 확인
$ git merge conflict-1 Auto-merging tigers.yaml CONFLICT (content): Merge conflict in tigers.yaml Automatic merge failed; fix conflicts and then commit the result.
$ git status On branch main You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both modified: tigers.yaml no changes added to commit (use "git add" and/or "git commit -a")

Accept Current Change 클릭하면

당장 충돌 해결이 어려울 경우 아래 명령어로 merge 중단
git merge --abort

해결 가능 시
- 충돌 부분을 수정한 뒤 git add .

main과 conflict1이 합쳐짐

2. rebase 충돌 해결
merge는 양쪽의 갈래를 한 번에 이어붙이는 것이기에 충돌 해결이 commit 한 번에 끝남
rebase는 branch 안에 있는 모든 커밋마다 충돌과정을 따로따로 차례로 해결해주어야 함
conflict-2에서 git rebase main로 리베이스 시도하면 충돌 발생
- 오류 메시지와 git status 확인
$ git rebase main Auto-merging leopards.yaml CONFLICT (content): Merge conflict in leopards.yaml error: could not apply 5c8fd8d... Edit Leopards hint: Resolve all conflicts manually, mark them as resolved with hint: "git add/rm <conflicted_files>", then run "git rebase --continue". hint: You can instead skip this commit: run "git rebase --skip". hint: To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply 5c8fd8d... Edit Leopards
$ git status interactive rebase in progress; onto db35937 Last command done (1 command done): pick 5c8fd8d Edit Leopards Next command to do (1 remaining command): pick a469a7c Edit Panthers (use "git rebase --edit-todo" to view and edit) You are currently rebasing branch 'conflict-2' on 'db35937'. (fix conflicts and then run "git rebase --continue") (use "git rebase --skip" to skip this patch) (use "git rebase --abort" to check out the original branch) Unmerged paths: (use "git restore --staged <file>..." to unstage) (use "git add <file>..." to mark resolution) both modified: leopards.yaml no changes added to commit (use "git add" and/or "git commit -a")
- both modified : 양쪽 파일에서 이 파일을 건드리려 한다. 개발자 당신이 해결해 달라
Accept Incoming Change 선택


당장 충돌 해결이 어려울 경우 아래 명령어로 rebase 중단
git rebase --abort
해결 가능 시
- 충돌 부분을 수정한 뒤 git add .
- 아래 명령어로 계속
git rebase --continue
마지막에 :wq로 commit


- 충돌이 모두 해결될 때까지 반복
main에서 git merge conflict-2로 마무리
conflict-1, conflict-2 삭제
'Git, Github 😺 > 제대로 파는 Git & GitHub - by 얄코' 카테고리의 다른 글
[Git, GitHub] GitHub에서 프로젝트 다운받기 (0) | 2024.01.20 |
---|---|
[Git, GitHub] GitHub와 작업 중인 프로젝트 연동 (GitHub와 IntelliJ 연동하기) (0) | 2024.01.20 |
[제대로 파는 Git & Github # 16] GitHub은 뭐고 왜 쓰나요? (0) | 2024.01.20 |
[제대로 파는 Git & Github # 15] SourceTree로 진행해보기 (0) | 2024.01.20 |