Friday, January 7, 2011

gitで複数のコミットを1つにまとめる

最新から4件のログを確認

git log -n 4 —oneline —reverse

rebase でコミットを編集する

git rebase -i HEAD~4

rebase による編集方法は エディット画面の下部に書いてある説明を参照。
pick の部分を、前のコミットと統合したい場所を fixup、コメントを変更したい場所をedit に変更。

# 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

edit を指定した場合、指定した過去のコミットまで状況が戻るので、
やりたい作業を行ったあとに git commit —amend を実行。
再コミットが終わったら、 git rebase —continue を実行して次のコミットに移る。

git commit —amend 

git rebase —continue

Notes