DEV/GIT
[GIT] git restore 를 이용한 staging area나 working directory 변화 취소
무사뎀벨레
2022. 1. 7. 11:10
git을 사용하여 형상관리를 하다 보면,
로컬에서 작업하고 있는 staging area나 working directory에서
작업하는 내용을 초기화할 경우가 종종 있습니다.
그럴 때 git restore 명령어를 사용하여 변경사항을 초기화할 수 있습니다.
git restore
- git 2.23 버전부터 작업 트리에서 수정한 파일 되돌리기 명령어가 변경되었습니다.
- git checkout -- test.txt => git restore test.txt
- git reset HEAD test.txt => git restore --staged test.txt
- cf) git 버전을 확인하려면 git --version 명령어를 사용
1. 파일이 working directory에 변경된 상황
git restore 파일명
- 위 이미지에서 working directory에 변경되었다고 나타나 있던 파일이 git restore 파일명 명령어를 사용한 뒤 변경 이전 사항으로 복구되었습니다.
2. 파일이 staging area에 add 가 된 상황
git restore --staged 파일명
//혹은
//HEAD가 가리키는 시점의 버전으로 파일을 unstage하고 되돌린다.
git reset HEAD 파일명
- 위 이미지에서 staging area에 add가 되어있던 main.html 파일이 git restore --staged 파일명 명령어를 사용한 뒤 working directory로 이동되었습니다.
반응형