git reset

henry·2024년 11월 14일

로컬 스토리지에서 작업한 파일이 Staging Area에 추가된 상황.

$ git add .
warning: in the working copy of 'package-lock.json', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'package.json', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'src/App.tsx', LF will be replaced by CRLF the next time Git touches it

18 files changed, 408 insertions(+), 40 deletions(-)
create mode 100644 src/components/books/BookItem.tsx
create mode 100644 src/components/books/BooksEmpty.tsx
create mode 100644 src/components/books/BooksFIiter.tsx
create mode 100644 src/components/books/BooksList.tsx
create mode 100644 src/components/books/BooksViewSwitcher.tsx
create mode 100644 src/components/books/Pagination.tsx
create mode 100644 src/pages/Books.tsx
create mode 100644 src/pages/Login.tsx
create mode 100644 src/pages/ResetPassword.tsx
create mode 100644 src/store/authStore.ts


특정 커밋 reset방법

1. 가장 최근 커밋 reset (소스 코드 유지)

가장 최근 커밋이 취소되며 작업 내용은 그대로 작업 디렉토리에 남는다.

git reset --soft HEAD~1

  • --soft 옵션
    • 커밋은 취소되지만, 변경 사항은 Staging Area에 남음
    • 이후 수정한 내용을 다시 커밋하려면 git commit을 실행하면 됨

2. Staging Area까지 취소 (변경 내용 유지)

Staging Area에 있는 파일까지 취소하려면 --mixed 옵션을 사용

git reset --mixed HEAD~1

  • 변경 내용은 작업 디렉토리에 남음
  • git add를 다시 해야 함

3. 작업 디렉토리까지 되돌리기 (모든 변경 사항 삭제)

커밋과 함께 작업 디렉토리의 변경 사항까지 되돌리고 싶다면 --hard를 사용

git reset --hard HEAD~1

  • 이 명령어는 복구 불가능하므로 신중히 사용
  • 작업 내용이 모두 삭제

0개의 댓글