티스토리 뷰

1. working directory를 마지막 push 시점으로 되돌리기

2. working directory를 이전 commit 시점으로 되돌리기

3. 특정 시점 특정 파일을 restore

 

1. working directory를 마지막 push 시점으로 되돌리기

git reset --hard origin/main # <repo>/<branch>, hard 옵션을 통해 working directory를 복구

reset 옵션 3가지

soft -> hard 순으로 영향 범위가 넓어진다.

1.--soft : branch ref

2.--mixed (default) : index

3.--hard : working directory

 

 

2. working directory를 이전 commit 시점으로 되돌리기

특정 파일 삭제 후 커밋

git rm testfile.txt # 삭제
git commit -m "remove testfile.txt for reset" # 커밋

로그 확인

git log -2 # 최근 2개 로그 확인

git reset --hard 13d251a73b457ffef011aae2c4e4840c55063cde # reset

 

 

3. 특정 시점 특정 파일을 restore

특정 파일 삭제

git rm src/test/Todo.vue # 파일 삭제
git commit -m "delete Todo.vue for restore test" # 커밋

로그 확인

삭제된 파일 full path를 얻기 위해 로그 확인시 파일목록도 함께 출력합니다.

# -2 : 최근 2개 로그만
# --name-status : 파일목록 표시
git log -2 --name-status

삭제되기 이전 상태인 밑줄친 시점으로 이동합니다. 해당 값은 commit hash로 불립니다.

# git restore --source <commit hash> <file path>
git restore --source 7061e5bfbcb68e737f95c771afa675a98ab77710 src/test/Todo.vue
git status

 

댓글