Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git 명령 및 설정
  6. Git 커밋 기록 명령
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Git 커밋 기록 명령


이전 커밋 및 메시지 수정

$ git commit --amend

작업 중인 브랜치의 최신 커밋을 덮어쓰려면 --amend 옵션을 추가합니다.

인덱스에 파일이 없는 경우 --amend 옵션을 추가하여 이전 커밋을 다시 커밋할 수 있으며 기존 커밋 메시지를 편집하라는 메시지가 표시됩니다.

참조:

과거 커밋 및 메시지 수정 및 이동

$ git rebase -i <commit>

커밋 해시를 추가하면 최신 커밋까지의 모든 커밋 목록이 나열됩니다. 수정하려는 커밋을 찾아 해당 라인을 pick에서 edit로 변경한 다음 저장하고 종료합니다.

다음으로 --amend 옵션을 추가하여 커밋합니다. 메시지를 추가하는 화면이 표시됩니다. 메시지를 수정합니다.

$ git commit --amend

마지막으로 --continue 옵션을 추가하여 rebase를 실행합니다.

$ git rebase --continue

참조:

리베이스 종료

$ git rebase --abort

--abort 옵션을 추가하면 리베이스 작업을 종료할 수 있습니다.

참조 로그 표시

$ git reflog

reflog 명령을 사용하면 HEAD가 과거에 표시하는 데 사용했던 커밋 목록을 볼 수 있습니다.

08084a5 HEAD@{0}: commit: append description of the pull command
  99daed2 HEAD@{1}: commit: append description of the commit command
  48eec1d HEAD@{2}: checkout: moving from main to issue1
  326fc9f HEAD@{3}: commit: append description of the add command
  48eec1d HEAD@{4}: commit (initial): first commit

rebase에 의해 수집된 삭제된 커밋과 성공한 커밋이 모두 표시됩니다.

브랜치 팁의 참조 로그 표시

$ git reflog <ref>

<ref>의 팁이 변경될 때마다 커밋 목록이 표시됩니다. 아래와 비슷합니다.

445e0ae issue1@{0}: commit (merge): Merge branch 'main' into issue1
1c904bd issue1@{1}: commit (amend): modify description of the pull command
08084a5 issue1@{2}: commit: append description of the pull command
99daed2 issue1@{3}: commit: append description of the commit command
48eec1d issue1@{4}: branch: Created from 48eec1ddf73a7fb508ef664efd6b3d873631742f

삭제된 커밋과 기존 커밋 모두의 리베이스 기록을 볼 수 있습니다.

이전 커밋 제거

$ git reset --hard HEAD~

참조:

리베이스 재설정

$ git reset --hard <commit>

reflog 명령v을 사용하여 리베이스되기 전에 커밋을 조회합니다. 리베이스 전에 발생한 커밋의 커밋 해시 또는 [HEAD@{숫자}] 값을 식별합니다. 이 예에서 71bdfbdHEAD@{4}는 커밋에 대한 참조입니다.

a51f8d2 HEAD@{0}: rebase -i (finish): returning to refs/heads/dev
  a51f8d2 HEAD@{1}: rebase -i (squash): update 1
  3a273e1 HEAD@{2}: rebase -i (squash): updating HEAD
  f55ef69 HEAD@{3}: checkout: moving from dev to f55ef69
  71bdfbd HEAD@{4}: commit: update 2
  f55ef69 HEAD@{5}: commit (amend): update 1

reset 명령을 실행할 때 해시 값(71bdfbdHEAD@{4})<commit>에 추가합니다.

브랜치의 헤드 위치는 이제 리베이스가 실행되기 전 커밋으로 이동합니다. 이제 브랜치의 상태는 리베이스가 실행되기 전의 상태와 동일합니다.

이전 재설정 취소

$ git reset --hard ORIG_HEAD

ORIG_HEAD는 재설정이 발생하기 전의 커밋을 나타냅니다. ORIG_HEAD로 재설정을 사용하여 이전 재설정을 되돌릴 수 있습니다.

다른 브랜치에서 커밋 복사

$ git cherry-pick "<commit>"

해시로 식별되는 커밋은 현재 브랜치에 복사됩니다.

참조:

커밋 메시지 검색

$ git log --grep "<pattern>"

<pattern>에 지정된 텍스트로 커밋을 표시합니다.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life