깃허브 - 충돌 시 해결법

지환·2023년 10월 4일
0

깃-오류

목록 보기
1/7

깃을 사용할 때 (아주 많고) 다양한 문제가 생길 수 있다.

각 이슈를 해결했던 방법을 기록하려 한다.

1.

hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
2.

Your branch and 'origin/[branch-name]' have diverged,
and have n and m different commits each, respectively.
(use "git pull" to merge the remote branch into yours)

git pull로 버전 맞춰주면 해결될 일.

3.

Your local changes to the following files would be overwritten by merge:
...
Please commit your changes or stash them before you merge.

git pull을 했을 때 이런 에러가 나왔다면 말 그대로 merge를 했을 때, 내가 해왔던 작업이 날라갈 수 있기에 에러가 나는 것. 이 때는 내가 한 작업들을 임시로 저장해주는 기능인 git stash를 해주고 git pull로 리모트에 있는 버전을 땅겨온 다음 git stash pop으로 임시저장소에 저장해놨던 나의 작업을 다시 불러오면 된다.

4.

Auto-merging project-cats/cat-app-client/src/sagas/user.jsx
CONFLICT (content): Merge conflict in project-cats/cat-app-client/src/sagas/user.jsx
? Automatic merge failed; fix conflicts and then commit the result.

나와 다른 개발자가 동시에 한 파일을 변경했을 떄, 어떤 변경사항을 어떻게 자동적으로 반영 (automatic merge) 해야할 지 몰라 뜨는 에러.
이런 경우는 에러가 뜨는 파일에 하나 하나 들어가, 어떤 코드를 선택할 지 정해줘야 한다.
하나 하나 선택해준 후 다시 푸시해주면 에러가 뜨지 않는다.

<<<<<<HEAD와 ====== 사이가 'Current Change'.
======와 >>>>>> ### 사이가 'Incoming Change'
둘 중 원하는 변동사항을 'Accept'해주면 된다.

conflict 에러가 너무 많이 뜨고
나는 그냥 나의 로컬을 현재 깃허브 상태로 덮어씌우고 싶을 때!

로컬에 있는 모든 내용을 강제로 덮어씌우는 방법


git fetch --all
git reset --hard origin/<branch_name>

참고 | https://piaflu.tistory.com/104

profile
아는만큼보인다.

0개의 댓글