勉強:過去のコミットコメントの修正方法
業務中、コメントの指摘を頂いて
過去のコミットコメントを直す機会に恵まれました。
コミットコメントについて調べたのでここにまとめます。
- git rebase -i <commit>
git rebase -i 664835c29bf5689d673b4f4349f2eaa3cfc85b23
という形で。
シリアル値にはどのコミットかを指定します。
上記のコマンドを打つと
以下のようなメッセージが表示されます。
pick 25787cf message2
pick d479e8f message3
# Rebase 664835c..d479e8f onto 664835c
#
# 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
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
変更したい「message2」の手前の、
「pick」という4文字を、
「reword」に変更してから、保存して、エディタを終了します。
もう一度エディタが起動し、「message2」を変更するためにコミットコメントを
入力できる画面になります。
ここで、「message2 modified」と入力すれば、コミットコメントは無事に変更されます。
解説の英文にしたがって変更を行えば問題ありません。
そして
rebaseの取りやめには
- git rebase —abort
を使用します。