Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git 사용 방법
  6. Git에서 기록을 관리하는 방법
  7. 이전 커밋 제거
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

이전 커밋 제거

이전에 다운로드한 git-tutorial/tutorial3 디렉터리로 이동합니다.

이 저장소의 기록을 검토하면 다음과 같이 표시됩니다.

Current history

Git reset 명령명령을 사용하여 이전 두 커밋을 취소할 것입니다.

먼저 sample.txt 파일을 열고 내용이 다음과 같은지 확인합니다.

Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
commit: Save the status of an index
pull: Obtain the content of the remote repository

아래와 같이 reset 명령을 사용하여 이전 두 커밋을 삭제합니다.

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

sample.txt 파일에는 더 이상 마지막 두 라인(예: "commit: Save the status of an index" 및 "pull: Obtain the content of the remote repository")이 포함되지 않습니다.

Git log 명령을 사용하여 이러한 커밋이 더 이상 기록에 없는지 확인합니다.

$ 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

ORIG_HEAD는 재설정이 발생하기 전의 원래 커밋을 가리킵니다. 이것은 실수로 재설정을 실행할 때 유용합니다.

ORIG_HEAD로 재설정을 실행하여 이전 기록을 복원할 수 있습니다.

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

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life