[Git] Branch merge 오류 해결하기

 

1️⃣강제 커밋 push하는 법


git push origin ‘branchName’ —force

 

 

2️⃣ git branch 병합문제 해결하기


원격저장소에 Branch가 A와 B로 나뉘어있다고 가정하자.

BranchA와 BranchB모두 파일 변경이 일어났으며, A가 먼저 원격저장소 master Branch에 병합이 되었다. 그 후, B에서 원격저장소에 push를 하려고 하면 merge 문제가 일어나게 된다. 따라서 원격저장소에서 변경된 사항을 B로 가져와야 한다.

 원격 저장소에서 변경된 사항을 가져오기


git fetch origin

git checkout [브런치명]

git pull origin develop //여기서 rebase에 대한 옵션을 설정해달라는 문구 나타남
힌트: You can do so by running one of the following commands sometime before
힌트: your next pull:
힌트: 
힌트:   git config pull.rebase false  # merge (the default strategy)
힌트:   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.

 원격 저장소의 pull에 대한 config


git config pull.rebase false //rebase 방식 옵션을 끔.

git pull origin develop // 이후 병합에 문제되는 사항을 확인
자동 병합: .../build.gradle
자동 병합: .../src/main/resources/application.yml
충돌 (내용): .../src/main/resources/application.yml에 병합 충돌
CONFLICT (modify/delete): .../src/main/resources/log4j2.xml deleted in HEAD and modified in ebe1fe780ea384d9215a765957d256de8324fcd9.  Version ebe1fe780ea384d9215a765957d256de8324fcd9 of startrip-codebase/src/main/resources/log4j2.xml left in tree.
자동 병합이 실패했습니다. 충돌을 바로잡고 결과물을 커밋하십시오.

충돌이 났다면 add > commit > 다시 원격 브런치 가져오기


이후, 다시 브런치B를 원격저장소에 push하면 된다