チュートリアル3 コミットを書き換えよう! 5. rebase -i でコミットをまとめる

このチュートリアルでは、あらかじめ履歴が準備されているローカルリポジトリを使用します。
こちらからダウンロードしてください。

stepup-tutorial/tutorial5ディレクトリに移動します。このリポジトリの履歴は次の図で表す状態になっています。
ここでは、「commitの説明を追加」と「pullの説明を追加」という変更を、ひとつのコミットにまとめます。

過去のコミットをまとめるには、rebase -iを使います。

$ git rebase -i HEAD~~

テキストエディタが開いて、HEADからHEAD~~までのコミットが次のように表示されます。

pick 05191fc commitの説明を追加
pick 05dc5b2 pullの説明を追加

# Rebase 82f0447..05dc5b2 onto d286baa
#
# 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に変更して保存・終了します。すると、まとめた後のコミットに設定するコミットメッセージを編集するためのエディタが表示されるので、編集して保存・終了します。

これで、二つのコミットが一つのコミットにまとめられました。logコマンドで履歴を確認してください。