inblog logo
|
{CODE-RYU};
    git

    git rebase

    Jan 02, 2024
    git rebase
    Contents
    로그 관리1. drop 사용2. reword 사용3. squash 사용하기
     
    💡
    git에서 브랜치(Branch) 를 합치는 방법.
     
    notion image
     
     

    로그 관리

    notion image
    git log // commit 로그 확인
    notion image
     
    테스트 폴더에 4개의 텍스트파일을 생성하고 각 파일 생성시 commit 완료
    git log 에서 빠져나오는 방법은 q를 누르면 된다.
     
     
    git rebase -i HEAD~숫자
    notion image
     
     
    HEAD 는 현재 브랜치의 가장 최신 commit 이고, ~숫자는 헤더를 기준으로 조회될 commit의 개수이다.
     

    1. drop 사용

    💡
    commit 삭제
    notion image
     
    입력모드에서 pick 을 d 로 변경하면 해당 commit 을 로그에서 삭제할 수 있다.
     
    notion image
     
    notion image
     
    단 실제 로그에서 사라지는 것은 아니다. git reflog 를 통해 이전 로그들을 확인할 수 있다.
     
    git reflog
    notion image
     
     
    git reset 을 활용해서 이전 commit 으로 복원 가능하다.
     
    notion image
    notion image
     
     

    2. reword 사용

     
    💡
    commit 이름 바꾸기
     
    notion image
     
    입력모드에서 변경 원하는 commit 의 pick 을 r 로 변경한다.
     
    notion image
     
    :wq 로 저장을 하면 새로운 창이 뜨는데 노란색 ‘연습하기싫음’ 을 원하는 이름으로 바꾸면 된다.
    notion image
     
     

    3. squash 사용하기

    💡
    commit 하나로 합치기
     
    squash 로 합칠 때는 가장 오래된 commit 을 기준으로 합쳐야 한다. 최신 코드를 기준으로 합칠 수 없다.
     
     
    notion image
    notion image
     
    notion image
     
    vi 에서 #은 주석이다. 이전 commit 이름을 지우고 원하는 이름으로 변경한다
     
    notion image
     
    Share article

    {CODE-RYU};

    RSS·Powered by Inblog