[Git] 삭제된 local branch 되돌리기

Ell!·2021년 10월 21일
0

git

목록 보기
1/1

사건 개요

열심히 백엔드랑 api연결을 하고서 까먹고 push를 안 해놓고 4시간 전에 했던 작업을 MVP와 merge를 시켜버렸다... 나중에 이걸 깨달아가지고 확인해보니깐 이미 local, origin 모두 해당 브랜치를 삭제해놓은 상황!! 식겁해서 해결방법을 찾아보기 시작했다.

해결 방법

다행히 git은 위대한지라 해결방법 역시 존재했다. git reflog로 내가 git을 사용한 모든 이력을 검색해서 지우기 이 전의 commit으로 돌아간 다음 다시 merge해서 push를 했다! 모든 것이...완벽❤

사용한 git 명령어 정리

git reflog  // git을 사용한 이력이 남는다.

$ git reflog
15caa7e (HEAD -> feauture/back, origin/feature/back-connect-auth) HEAD@{0}: checkout: moving from MVP to feauture/back
6ef25c3 (origin/MVP, feature/profile-game-list, MVP) HEAD@{1}: checkout: moving from feature/back-connect-auth to MVP 
ce5aadf HEAD@{2}: checkout: moving from MVP to feature/back-connect-auth
6ef25c3 (origin/MVP, feature/profile-game-list, MVP) HEAD@{3}: reset: moving to HEAD
6ef25c3 (origin/MVP, feature/profile-game-list, MVP) HEAD@{4}: checkout: moving from feature/profile-game-list to MVP
6ef25c3 (origin/MVP, feature/profile-game-list, MVP) HEAD@{5}: checkout: moving from MVP to feature/profile-game-list
6ef25c3 (origin/MVP, feature/profile-game-list, MVP) HEAD@{6}: commit: [Add] 프
로필 페이지 404 추가
fe4bb63 HEAD@{7}: pull origin MVP: Fast-forward
ce5aadf HEAD@{8}: checkout: moving from feature/back-connect-auth to MVP
494c211 HEAD@{9}: checkout: moving from MVP to feature/back-connect-auth
ce5aadf HEAD@{10}: checkout: moving from feature/back-connect-auth to MVP
494c211 HEAD@{11}: commit: [Add] 회원가입 후 프로필 모달, 게임계정등록 모달 오픈
a48bcf6 HEAD@{12}: commit: [Add] 게스트 헤더에서 로그아웃 구현
cb7e2d5 HEAD@{13}: commit: [Update] 게스트 로그인 모달 닉네임 입력, 게임 계정 입력 분리
d16bbc6 HEAD@{14}: commit: [Add] profile page 404 처리
15caa7e (HEAD -> feauture/back, origin/feature/back-connect-auth) HEAD@{15}: commit: [Add] 프로필 페이지 프로필 모달 업데이트 변경 후 실시간 
변경
ebcd432 HEAD@{16}: commit: [Add] 프로필 페이지 get, update 연결
ca2a550 HEAD@{17}: commit: [Add] 자기 프로필만 수정 가능하도록



커밋 복구
git reset --hard <commit해시id>

git checkout -b <삭제한브랜치명> <커밋해시id>

profile
더 나은 서비스를 고민하는 프론트엔드 개발자.

0개의 댓글