git rebase로 commit 합치기
git rebase -i HEAD~[숫자]
자신이 여러번 commit 한 내용을 하나로 합치고 싶을 경우 사용한다.
git rebase -i HEAD~3
위 명령어를 입력하게 되면 아래와 같은 메세지가 출력된다.
$ git rebase -i HEAD~2
pick 004644d first commit
pick ae53bdf second commit
pick as4sef5 third 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
first commit에 second, third commit을 합치기 위해서 두번째, 세번째의 pick을 squash
로 변경한 뒤 :wq(저장)한다.
# This is a combination of 3 commits.
# This is the 1st commit message:
first commit
# This is the commit message #2:
second commit
# This is the commit message #3:
third commit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Tue Mar 14 21:50:01 2017 +0900
#
# interactive rebase in progress; onto f42adb4
# Last commands done (2 commands done):
# pick 004644d first commit
# s ae53bdf second commit
# No commands remaining.
# You are currently editing a commit while rebasing branch 'master' on 'f42adb4'.
#
# Changes to be committed:
# modified: test.txt
#
저장하게 되면 위의 메세지가 출력되는데, 이는 통합한 뒤 생기는 commit의 메세지를 입력해달라는 창이다.
자신이 원하는 commit message를 입력한 뒤 저장한다.
꼭 최근 커밋으로만 합치는 게 가능한 것은 아니고 합쳐지길 원하는 commmit에 squash
를 입력하면 된다.
댓글남기기