[ git ] 하나의 브랜치에서 여러 PR 작업으로 인한 Conflict 해결하기

신범철·2023년 3월 18일
0

github

목록 보기
6/6

🪄문제 상황

branch(master)에서 파생된 branch(beom1)에서 PR을 올린 뒤 merge하고 이어서 branch(beom1)에서 작업을 이어 갔다. 이 후 PR을 올려보니 이전 PR에 있는 commit까지 같이 올라갔고 conflict로 인해 merge가 불가능하다는 문제가 발생하였다.

  1. branch(beom1)에서 commit1과 commit2를 작업 후 pr을 올렸다.

  2. 이후 pr을 master로 merge하는 작업을 하였다.

  3. 바로 이어서 branch(beom1)에서 commit3, commit4, commit5를 작업 후 PR을 올렸더니 해당 PR에 이전 PR에 있던 commit1과 commit2가 찍혀있어 conflict가 나는 상황이다.

🪄해결방안

1. merge를 통해 conflict를 해결하고 새로운 커밋을 찍어 올리는 방법

단점!! : commit3, commit4, commit5의 내용이 사라지고 새로운 commit6으로 합쳐서 만들어진다.

  1. 로컬의 branch(master)에서 깃허브 branch(master)를 pull한다.(git pull origin master)
  2. 혹시 모르는 상황을 대비해 마스터 말고 임시 브랜치 생성(git checkout -b beom2)
  3. branch(beom2)에서 branch(beom1)을 merge한다.(git merge beom1)
  4. resloved conflict로 conflict를 모두 branch(beom1)로 바꿔준다.
  5. 새로운 커밋(commit6)를 찍고 PR을 올리면 충돌 해결

2. cherry-pick을 통해 커밋을 가져오기

commit1과 commit2가 pull된 branch(master)에서 branch(beom1)의 commit3, commit4, commit5만 가져오기

  1. 로컬의 branch(master)에서 깃허브 branch(master)를 pull한다.(git pull origin master)
  2. 혹시 모르는 상황을 대비해 마스터 말고 임시 브랜치 생성(git checkout -b beom2)
  3. branch(beom1)의 commit3, commit4, commit5를 branch(beom2)로 가져온다.(git cherry-pick 07397fa 01d193d e757576)
  4. 이후 새로운 커밋을 찍고 PR을 올리면 충돌 해결!!
profile
https://github.com/beombu

0개의 댓글