현재 git 상태
$ git log
commit 377d43677d6a2ff0f851a584bd27265b77f5f7ec (HEAD -> master)
Author: mohadangKim <ehdlaos@gmail.com>
Date: Sat Jan 7 18:37:03 2023 +0900
add 123
commit 40aebbf5cc13a5fd66454050b617a8174dc90b35
Author: mohadangKim <ehdlaos@gmail.com>
Date: Sat Jan 7 18:36:33 2023 +0900
add def
commit 7d24549eeac89f38840816cbcc6ad2222ca041cf
Author: mohadangKim <ehdlaos@gmail.com>
Date: Sat Jan 7 18:36:10 2023 +0900
add abc
commit d3337f47d70342309e2ce83e9c81903c41363321
Author: mohadangKim <ehdlaos@gmail.com>
Date: Sat Jan 7 18:35:43 2023 +0900
add a.txt
여기서 add 123, add def commit을 통합하여 새로운 commit으로 만들려면
$ git rebase -i HEAD~~
마지막 commit에 대해 pick을 squash로 변경한 후 저장
pick 40aebbf add def
# pick 377d436 add 123
squash 377d436 add 123
# Rebase 7d24549..377d436 onto 7d24549 (2 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# 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에 대한 새로운 커밋 메시지 작성 후 저장
# This is a combination of 2 commits.
# This is the 1st commit message:
add def
# This is the commit message #2:
add 123
윗부분의 내용을 지우고 새로운 커밋 메시지 작성하면 된다.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Sat Jan 7 18:36:33 2023 +0900
#
# interactive rebase in progress; onto 7d24549
# Last commands done (2 commands done):
# pick 40aebbf add def
# squash 377d436 add 123
# No commands remaining.
# You are currently rebasing branch 'master' on '7d24549'.
#
# Changes to be committed:
# modified: a.txt
통합된 커밋 로그를 확인할 수 있다.
$ git log
commit efe63098c91cae5b0e6943b4c9c2c26e55fff4ea (HEAD -> master)
Author: mohadangKim <ehdlaos@gmail.com>
Date: Sat Jan 7 18:36:33 2023 +0900
new commit message
commit 7d24549eeac89f38840816cbcc6ad2222ca041cf
Author: mohadangKim <ehdlaos@gmail.com>
Date: Sat Jan 7 18:36:10 2023 +0900
add abc
commit d3337f47d70342309e2ce83e9c81903c41363321
Author: mohadangKim <ehdlaos@gmail.com>
Date: Sat Jan 7 18:35:43 2023 +0900
add a.txt