[Git] git rebase

민병대·2023년 3월 20일
0

1. rebase란?

브랜치의 베이스를 옮기는 작업.
커밋 이력을 남기지 않아 커밋 히스토리가 깔끔해진다.

2.git rebase --interactive

커밋 히스토리를 수정
git rebase -i HEAD~3

pick 9a54fd4 commit의 설명 추가
pick 0d4a808 pull 설명을 추가

# 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.
#

pick을 squash (s)로 변경하면 여러개의 커밋을 하나의 커밋으로 합칠 수 있다.

  • 이미 push 한 커밋을 squash 한다면 git push -f

3. rebase 취소하기

git rebase --abort

profile
마케터 출신 개발자

0개의 댓글