git rebase로 커밋 합치기

Tony·2021년 12월 7일
0

github

목록 보기
18/23

상황

  • github PR(Pull Request)을 올렸는데 리뷰과정에서 작은 수정이 생긴 경우
  • 리뷰과정에서 생긴 커밋 - 한두줄 수정된 것을 커밋 - 을 깔끔하게 하나의 커밋으로 합치고 싶은 상황

git rebase

git rebase -i HEAD~[합칠 커밋 개수]

git rebase -i HEAD~2
$ git rebase -i HEAD~2
pick 004644d first commit // 처음 올린 커밋에 
pick ae53bdf second commit // 두번째 올린 커밋을 합치고 싶은 경우

# Rebase f42adb4..ae53bdf onto f42adb4 (2 commands)
#
# 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
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

합치기

$ git rebase -i HEAD~2
pick 004644d first commit
s ae53bdf second commit // squash로 합친 다는 뜻

# Rebase f42adb4..ae53bdf onto f42adb4 (2 commands)
#
# 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
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
  • 수정 후 :wq 명령어로 저장
  • git log로 잘 수정되었는지 확인

기존 PR에 덮어쓰기

git push -f origin [브랜치명]

참고

profile
움직이는 만큼 행복해진다

0개의 댓글