프로젝트때 팀원 분의 코드를 pull 하려다가, 오류가 났다.
오류가 난 경위는
dev-FE폴더에서 파생된 fe/signin브랜치가 있는데,
dev-FE에서
git pull origin dev-FE
로 pull 당겨온 후,
코드가 잘 들어간 것을 확인하고 fe/signin 브랜치로 가서 git pull origin dev-FE
를 했지만,
mac@macs-MacBook-Air client % git pull origin dev-FE
https://github.com/Petching/Petching URL에서
- branch dev-FE -> FETCH_HEAD
힌트: You have divergent branches and need to specify how to reconcile them.
힌트: You can do so by running one of the following commands sometime before
힌트: your next pull:
힌트:
힌트: git config pull.rebase false # merge
힌트: git config pull.rebase true # rebase
힌트: git config pull.ff only # fast-forward only
힌트:
힌트: You can replace "git config" with "git config --global" to set a default
힌트: preference for all repositories. You can also pass --rebase, --no-rebase,
힌트: or --ff-only on the command line to override the configured default per
힌트: invocation.
fatal: Need to specify how to reconcile divergent branches.
이런 오류를 마주했다. 살펴보면 dev-FE와 fe/signin에 서로 다른 분기가 있다는 뜻이다.
git은 변경 사항을 가져올 때 이를 조정해야 하기 때문에, rebase 옵션을 쓸지 정해야 한다.
git pull origin --no-rebase
git pull origin --rebase
: 원격 분기의 최신 커밋 위에 로컬 커밋을 적용함
git pull origin --ff-only
: fast-forward only : 빨리 감기 병합을 허용하지만, 빨리 감기가 가능하지 않은 경우 병합 커밋을 생성하지 않는다.
나는 fe/signin 브랜치에서
git pull origin dev-FE --rebase
를 사용했지만, dev-FE에서는 팀원분의 코드를 받은 상태였고,
fe/signin 브랜치에서는 나의 코드만 따로 추가되고 팀원분의 코드를 받지 않은 상황이라,
내가 만든 컴포넌트가 몇 개 추가 되지 않는 상황이었다.
그래서 rebase를 취소하고 다시 merge를 해야했다.
git status
git rebase --abort
로 병합을 취소하고,
git reflog
로 리베이스 전에 커밋 참조를 찾고 분기를 해당 상태로 재설정할 수 있었다.
이후에,
git checkout fe/signin
git fetch origin
git merge origin dev-FE
dev-FE에 머지 후
git add .
git commit -m "something message"
git push origin fe/signin
해주면 dev-FE에는 내가 작성한 signin 코드가 추가된다.