[Git] interactive rebase

Inhye Jeong·2020년 11월 9일
0

Git

목록 보기
5/7

1. git rebase -i 알아보기

git 을 사용하다 보면,
이미 커밋한 히스토리를 변경하거나 또는 삭제하거나,
내용을 추가해야하는 상황이 자주 발생합니다.

이때 사용할수 있는 명령이 바로 $git rebase -i 입니다.
-i--interactive의 약어로 말 그대로 git rebase 명령어를 대화형으로 실행하겠다는 의미입니다.

2. 언제 유용?

다수의 feature 브랜치가 merge 된 epic branch를 main 브랜치로 merge하는 상황

1) 특정 커밋이 main에는 merge되면 안되는 경우가 발생

  • 이 상황에서는 특정 커밋만 없애고 싶어서 rebase -i를 사용했다. 정확히 말하면 리베이스를 하면서 특정 커밋을 drop하고 싶어서.

2) 차례대로 아래 명렁어 실행

$ git checkout epic
$ git rebase -i main

3) 수정이 필요한 커밋에 명령어를 변경

2)의 명령어를 실행하면 editor로 main 브랜치로 쌓아올릴커밋 리스트가 보인다. 각 명령어를 필요에 따라 수정하고 save.

  • 명령어 예시
# Rebase 326fc9f..0d4a808 onto d286baa
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

4) conflict이 난다면 해결하고 rebase 지속

$ git rebase --continue


profile
Frontend Engineer in @KakaoStyle

0개의 댓글