[Git] 커밋 취소 : reset, revert

한별·2023년 9월 22일
0

Git

목록 보기
7/13
post-thumbnail

⭐ reset

💫 사용 예제

2개의 커밋을 취소할 것임

1. 명령어 실행

$ git reset --hard HEAD~~
  HEAD is now at 326fc9f append description of the add command

2. 실행 결과

$ git log
  commit 326fc9f70d022afdd31b0072dbbae003783d77ed
  Author: yourname <yourname@yourmail.com>
  Date:   Mon Jul 16 23:17:56 2022 +0900

      append description of the add command

  commit 48eec1ddf73a7fb508ef664efd6b3d873631742f
  Author: yourname <yourname@yourmail.com>
  Date:   Mon Jul 16 23:16:14 2022 +0900

      first commit

⚠️ Reset 실수를 한 경우 : 복원

ORIG_HEAD는 재설정이 발생하기 전의 원래 HEAD 커밋을 가리킴
따라서 ORIG_HEAD로 reset을 실행하면 이전 기록을 복원 가능

$ git reset --hard ORIG_HEAD
  HEAD is now at 0d4a808 append description of the pull command

⭐ revert

💫 사용 예제

마지막 커밋을 실행 취소할 것임

1. 명령어 실행

$ git revert HEAD
[main d47bb1d] Revert "append description of the pull command"
  1 files changed, 1 insertions(+), 2 deletions(-)

2. 실행 결과

$ git log
  commit 7bcf5e3b6fc47e875ec226ce2b13a53df73cf626
  Author: yourname <yourname@yourmail.com>
  Date:   Wed Jul 18 15:46:28 2022 +0900

      Revert "append description of the pull command"

      This reverts commit 0d4a808c26908cd5fe4b6294a00150342d1a58be.

  commit 0d4a808c26908cd5fe4b6294a00150342d1a58be
  Author: yourname <yourname@yourmail.com>
  Date:   Mon Jul 16 23:19:26 2022 +0900

      append description of the pull command

(생략)

⭐ Reset vs. Revert

Reset은 과거의 상태로 완전히 돌아가고
Revert는 과거의 상태를 재현한 revert commit을 추가함


참고 자료

[nulab] 커밋 취소
[nulab] 이전 커밋 제거

profile
누구나 이해하기 쉽게 글 쓰고 싶은 FE 개발자

0개의 댓글

관련 채용 정보