Editing a Commit Message in git

To correct a typo in a git commit message, get the hash of the commit, e.g. by using git log:

commit dbdb363a50cc93a0e7612a2d160b8fcb53ac1e3d
Author: Ralf Bensmann <ralf@art-of-coding.eu>
Date:   Sat Dec 29 14:17:38 2012 +0100

    Java 7

commit bf9f51b07ff4c269970b4f8e75c74b14e5b295c5
Author: Ralf Bensmann <ralf@art-of-coding.eu>
Date:   Sat Dec 29 14:17:29 2012 +0100

    Improved documentatiob

and git rebase --interactive:

rbe:~/project/example @develop $ git rebase --interactive 2e22596f24bcc7410900fdb5c0845d2afb917122

You’ll get a list of your commits, change pick to reword:

pick b2b7d11 Improved documentatiob
pick d639ce7 Java 7

# Rebase 2e22596..d639ce7 onto 2e22596
# 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

Like this:

reword b2b7d11 Improved documentatiob
pick d639ce7 Java 7

And save and exit the editor, in vi it is ESC :x.

Next step is to edit the message: Changing Improved documentatiob to Improved documentation and save and exit again.

Now you have a better commit message:

[losgelöste Zweigspitze (HEAD) b2b7d11] Improved documentation
 1 file changed, 6 insertions(+), 6 deletions(-)
Successfully rebased and updated refs/heads/develop.

and you should go ahead and for example git push your changes.


This entry was posted in Software Development, Tooling and tagged , . Bookmark the permalink.