💽 CICD/Git

[Git] 충돌 (Conflict)

heywantodo 2023. 4. 25. 16:13
728x90
반응형

[Git] 충돌 (Conflict)

1. Merge 과정에서 발생하는 충돌

Merge 과정 중 충돌이 발생했을 때

 

1️⃣ Merge 취소

--abort 옵션으로 취소 후 status로 상태 확인

git merge --abort
git status

 

2️⃣ 충돌이 난 파일 수정

충돌이 난 파일의 이름이 myfile일 때, myfile을 확인 후 수정

파일을 열어보면 어느부분에서 충돌이 났는지 확인 할 수 있고, 수정하면 됨

<<<<<<< HEAD
hello
=======
hello world
>>>>>>> master
hello world

 

3️⃣ 충돌이 난 파일 add 후 다시 commit

git add myfile
git commit -m "resolve coflict!"

 

2. Rebase 과정에서 발생하는 충돌

Rebase 과정에서 충돌이 일어날 경우, Rebase가 진행되지도 끝나지도 않고 중간에 멈추게 됨

 

1️⃣ 충돌이 난 파일 수정

<<<<<<< HEAD
hello
=======
hello world
>>>>>>> master
hello world

 

2️⃣ add

파일 수정 후 add

git add .

 

3️⃣ rebase 진행

아래 명령어를 실행하면 멈춰있던 rebase가 진행됨

git rebase --continue

❗ 충돌이 여러번 일어났을 경우, 충돌이 일어난 만큼 git add . > git rebase --continue과정을 반복 

 

4️⃣ push

--amend 옵션으로 최상단 메세지만 남긴 후 다 지워준 뒤 푸쉬

git commit --amend
git push origin master

 

🤔 만약 해결이 안된다면 rebase 취소 

git rebase --abort

 

 

참조

https://blog.naver.com/PostView.naver?blogId=codeitofficial&logNo=221938658754&redirect=Dlog&widgetTypeCall=true&directAccess=false

https://velog.io/@dev_cecy/GitGithub-Git-Merge%EC%99%80-Rebase%EC%9D%98-%EC%B0%A8%EC%9D%B4%EC%A0%90

728x90
반응형