Version Control

git. branch를 지워버렸을때 복구하는 법

out of coding 2019. 3. 25. 13:51

git branch를 지워버렸을때 복구하는 법에 대해서 알아봅시다.


다음과 같이 하면 되긴 합니다.


1
2
3
$ git branch # check 
$ git reflog 
$ git checkout -b [deleted-branchName] HEAD@{number}
cs


이유는 git은 사실 모든 동작을 파일로 만들어 둔다고 합니다.

그래서 새로 commit하거나 branch를 변경하는 작업을 하여도 reflog는 늘어나게 됩니다.


git update-ref를 사용하여서 남길수도 있다고 합니다.


참조 : https://git-scm.com/book/ko/v1/Git%EC%9D%98-%EB%82%B4%EB%B6%80-%EC%9A%B4%EC%98%81-%EB%B0%8F-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EB%B3%B5%EA%B5%AC