ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • git 에서 여러개의 commit 로그를 합치는 방법
    카테고리 없음 2025. 1. 17. 13:32
    728x90

    git rebase로 여러 커밋 합치기 (squash)

    1. 대상 커밋 찾기

     
    $ git log --oneline

     

    a1b2c3e Fix a minor bug
    d4e5f6a Add error handling
    b7c8d9f Initial commit
     

    여기서 a1b2c3e와 d4e5f6a 두 커밋을 합치고 싶다고 가정합니다.


    2. git rebase -i 실행

    $ git rebase -i HEAD~n
    • HEAD~n에서 n은 합치고자 하는 마지막 커밋을 포함한 최근 커밋의 수입니다. 예: 위에서 최근 2개의 커밋을 합치려면:
      $ git rebase -i HEAD~2

    3. Rebase Interactive 모드에서 커밋 결합 (Squash)

    • Interactive 모드에서 다음과 같은 화면이 나타납니다:
      pick d4e5f6a Add error handling
      pick a1b2c3e Fix a minor bug
    • 두 커밋을 합치려면 첫 번째 커밋(맨 위의 pick)은 그대로 두고, 나머지는 squash 또는 s로 바꿉니다:
      pick d4e5f6a Add error handling
      squash a1b2c3e Fix a minor bug

    4. 커밋 메시지 병합

    • 다음 화면에서 합칠 커밋 메시지가 표시됩니다:
      # This is a combination of 2 commits.
      # The first commit’s message is:
      Add error handling
      # The following commit message will also be included:
      Fix a minor bug
    • 메시지를 수정해 단일 메시지로 통합하거나 그대로 둡니다:
      Add error handling and fix a minor bug
    • 파일을 저장하고 종료하면 Rebase가 완료됩니다.

    5. 결과 확인

    $ git log --oneline

    압축된 단일 커밋으로 합쳐진 것을 확인할 수 있습니다.

    728x90
Designed by Tistory.