[git] restore, clean 을 이용하여 로컬 변화 취소하기 (feat. reset)

younoah·2021년 2월 7일
2

[Git]

목록 보기
9/14

Discard Local change (로컬 변화 취소하기)

로컬에서 작업하고 있는 staging area나 working directory에서 작업하는 내용을 초기화 하는 방법에 대해서 알아보자.

unstaging a staged file

git restore --staged 파일명
git reset HEAD 파일명 # HEAD가 가리키는 시점의 버전으로 파일을 unstage하고 되돌린다.
  • 명령어 수행 전

  • 명령어 수행 후

초록색은 staging area에 있는 상태

빨간색은 working directory에만 있는 상태

unmodifing a modified file

git restore 파일명

modified 내용 삭제한다. 즉, 수정한 내용을 삭제해버리고 기존 상태로 되돌린다.

remove untracked files

git clean -fd # 옵션 -f: force, -d: diretory 포함

모든 untracked file을 삭제한다.

restoring file from certain commit

git restore --source=해시코드 파일명
git restore --source=HEAD~2 파일명 # HEAD와 같은 포인터도 사용가능

파일을 특정 커밋 버전의 상태로 되돌린다.

profile
console.log(noah(🍕 , 🍺)); // true

0개의 댓글