✲゚。.ヾ(⌒(ノ'ω')ノ☆.。

変色系男子の日常。

過去のコミットをまとめてみよう

細かく上げたコミットや後で修正した際のコミットをまとめたくなる時ってあるよね。
そんな時も Git なら安心です♪

$ git rebase -i HEAD~3

上のコマンドだと最新のものから3つまでをまとめることが出来る。

pick aaaaaaa ほむほむした。
pick bbbbbbb さやさやした。
pick ccccccc まどまどした。

# Rebase aaaaaaa..ccccccc onto aaaaaaa
#
# 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*1 もしくは s に書き換える。

pick aaaaaaa ほむほむした。
s bbbbbbb さやさやした。
s ccccccc まどまどした。

# Rebase aaaaaaa..ccccccc onto aaaaaaa
#
# 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.
#

最後に以下のコミットメッセージを任意のものに書き換えれば OK!

# This is a combination of 3 commits.
# The first commit's message is:
ほむほむした。

# This is the 2nd commit message:

さやさやした。

# This is the 3rd commit message:

まどまどした。

ちなみに rebase に失敗して git rebase -i を再実行したときに、
Interactive rebase already started と怒られるようになってしまった場合は、
以下のコマンドでリベース作業を中断すれば OK!

$ git rebase --abort

*1:squash はペチャンコにするって意味らしいよ。スカッシュ!