Github master branch에 pull request로 merge한 내역 원복하기

2021-12-13

.

Data_Engineering_TIL(20211213)

[문제상황]

pull request로 마스터 브랜치에 어떤 수정한 이력을 반영을 했다고 가정하자.

그런데 이렇게 반영한 내역이 잘못된 내용이라 원상복구를 해야하는 상황이 왔다고 하자.

작업branch –> master로 pull request로 merge하기전에 작업branch에 push한 commit id가 b6e7a0de3fddqkwlcdnqlkwndlqaa4ae128라고 하자.

결론적으로 pull request로 마스터 브랜치에 어떤 수정한 이력을 원상복구 시키려고 한다.

[해결방법 요약]

STEP 1) 임시 브랜치 생성

STEP 2) git revert 명령어로 일전에 작업해서 작업branch에 push해서 얻은 commit id b6e7a0de3fddqkwlcdnqlkwndlqaa4ae128의 직전 단계로 commit 내역 원상복구

STEP 3) 임시 브랜치를 원격 저장소에 Push

STEP 4) 임시 브랜치를 master 브랜치로 merge

[해결방법]


$ git checkout master

$ git pull origin master

# hotfix/my_temp_branch라는 임시 브랜치 생성
$ git branch hotfix/my_temp_branch

# hotfix/my_temp_branch로 변경
$ git checkout hotfix/my_temp_branch

# git revert {원복 commit_id}
# 일전에 작업해서 작업branch에 push해서 얻은 commit id b6e7a0de3fddqkwlcdnqlkwndlqaa4ae128의 직전 단계로 commit 내역 원상복구
$ git revert b6e7a0de3fddqkwlcdnqlkwndlqaa4ae128

$ git push

웹브라우저로 가서 해당 깃허브 레포지토리로 이동한 다음 hotfix/my_temp_branch로 전환해서 master branch에 pull request하고 merge 처리하면 된다.