우리 팀 git workflow 는 feature 나 hotfix branch 에서 작업 후 push 를 하고 main branch 에 merge request 를 하는 방식을 취하고 있다. work branch 에 여러번 나눠서 commit 된 내용들을 합쳐서 올릴 때 squash 를 사용한다.

최근 N 개의 commit 을 합침, 제거, 메시지 수정을 하고 싶을 때 rebase 를 사용하게 된다.

> git rebase -i HEAD~N

아래와 같은 내용이 출력된다. 

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

합치고 싶은 commit 을 squash (or s) 로 바꿔주고 저장하면 된다.

pick 004644d first commit
squash ae53bdf second commit

로그를 수정할 수 있는 화면이 출력된다.

# This is a combination of 2 commits.
# This is the 1st commit message:

first commit

# This is the commit message #2:

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

참고 : git rebase 로 commit 합치기

728x90

+ Recent posts