Git 변경 사항 되돌리기

sookyeong·2022년 3월 30일
0

1. Local 변경 사항 되돌리기

전체 파일을 마지막 Commit으로 되돌리기

$ git checkout .

특정 파일에 대한 변경 사항만 되돌리기

$ git checkout '파일명'

2. Add 되돌리기

전체 파일을 Unstage

$ git reset HEAD

특정 파일만 Unstage

$ git reset HEAD '파일명'

3. Commit 되돌리기 (주의)

Commit을 취소하고 해당 파일들은 Staged 상태로 Working Directory에 보존하기

$ git reset --soft HEAD^

Commit을 취소하고 해당 파일들은 Unstaged 상태로 Working Directory에 보존하기

$ git reset --mixed HEAD^  # 기본 옵션
$ git reset HEAD^  # 위와 동일
$ git reset HEAD~2  # 마지막 2개의 commit을 취소

Commit을 취소하고 해당 파일들은 Unstaged 상태로 Working Directory에서도 삭제하기

$ git reset --hard HEAD^

4. 과거로 갔다가 현재로 돌아오기

과거로 돌아가기

$ git checkout HEAD~1  # 한 단계 전으로 돌아가기
$ git checkout HEAD~4  # 네 단계 전으로 돌아가기

다시 돌아오기

$ git checkout [Branch명]
profile
actions speak louder than words

0개의 댓글