Git Update Commit Message

By  on  

One of my faults as a professional developer is that my commit messages aren't always as descriptive as they could be.  Sometimes I even notice a spelling error in them.  Bleh -- that's not cool, man.  When I do catch that my last commit message isn't good enough, I find the following git command useful:

The command below rewrites the message for the previous commit.  You can omit the -m and message to go into the commit shell instead.

git commit --amend -m "This is the new message"

Do realize, however, that performing this after you've pushed to a remote repo is considered bad as it rewrites history. If you haven't pushed, however, the command above is gold!

Recent Features

  • By
    LightFace:  Facebook Lightbox for MooTools

    One of the web components I've always loved has been Facebook's modal dialog.  This "lightbox" isn't like others:  no dark overlay, no obnoxious animating to size, and it doesn't try to do "too much."  With Facebook's dialog in mind, I've created LightFace:  a Facebook lightbox...

  • By
    Chris Coyier’s Favorite CodePen Demos

    David asked me if I'd be up for a guest post picking out some of my favorite Pens from CodePen. A daunting task! There are so many! I managed to pick a few though that have blown me away over the past few months. If you...

Incredible Demos

  • By
    Rotate Elements with CSS Transformations

    I've gone on a million rants about the lack of progress with CSS and how I'm happy that both JavaScript and browser-specific CSS have tried to push web design forward. One of those browser-specific CSS properties we love is CSS transformations. CSS transformations...

  • By
    Style Textarea Resizers

    Modern browsers are nice in that they allow you to style some odd properties.  Heck, one of the most popular posts on this blog is HTML5 Placeholder Styling with CSS, a tiny but useful task.  Did you know you can also restyle the textarea resizer in WebKit...

Discussion

  1. This is one of the things I do more frequently :-/

    The good thing is that, with amend, you can also include in the commit new changes (provided that you have added them to the staging area).

    The drawback is that it’s **bad** to amend a commit that has already been pushed to a remote repository.

  2. May I point you to an article of my own, in which I describe some more solutions on how to change commit messages:

    http://www.gamez.name/change-commit-message-git/

  3. Dorian Marchal

    Be careful, this command rewrites history and shouldn’t be used if you already pushed your last commit.

  4. And you are noticing it now? :D

    One thing to remember is HASH is changed on amending.

  5. And you are noticing it now? :D

    Well, one thing to notice is that HASH of that particular commit is rewritten when amending.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!