RoBoLoG

[Git] commit 시점으로 파일 되돌리기 본문

Error Solution/Etc

[Git] commit 시점으로 파일 되돌리기

SKJun 2022. 12. 21. 18:07

Git으로 작업하다가 push 이후 갑자기 파일이 날아갔을 때 당황하지 말자

 

1. commit 로그 확인 

 

터미널에 다음과 같이 입력하여 commit 로그를 확인한다.

 

git reflog

 

그러면 commit 로그를 확인할 수 있으며, 맨 앞에 숫자/알파벳 배열은 commit id이다.

 

1f924e9 (HEAD -> devel, origin/devel) HEAD@{0}: commit: display and expression
8180870 (master) HEAD@{1}: reset: moving to 8180870
f7ce8ed HEAD@{2}: checkout: moving from devel to devel
f7ce8ed HEAD@{3}: checkout: moving from master to devel
8180870 (master) HEAD@{4}: commit: display and expression recognition added
5c1cc32 HEAD@{5}: commit: identification added
dfb2531 HEAD@{6}: commit: identification added
f7ce8ed HEAD@{7}: commit (initial): Initial commit

 

여기서 commit_id가 8108870인 시점으로 되돌아가도록 하겠다.

 


2. commit 시점으로 되돌아가기

 

git reset을 이용하여 commit 시점으로 되돌아간다.

 

commit_id에 8108870을 넣어주면 해당 시점으로 되돌아가진다.

 

git reset --hard commit_id

 

728x90
반응형