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
    Write Simple, Elegant and Maintainable Media Queries with Sass

    I spent a few months experimenting with different approaches for writing simple, elegant and maintainable media queries with Sass. Each solution had something that I really liked, but I couldn't find one that covered everything I needed to do, so I ventured into creating my...

  • By
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

Incredible Demos

  • By
    HTML5 Context Menus

    One of the hidden gems within the HTML5 spec is context menus. The HTML5 context menu spec allows developers to create custom context menus for given blocks within simple menu and menuitem elements. The menu information lives right within the page so...

  • By
    Save Web Form Content Using Control + S

    We've all used word processing applications like Microsoft Word and if there's one thing they've taught you it's that you need to save every few seconds in anticipation of the inevitable crash. WordPress has mimicked this functionality within their WYSIWYG editor and I use it...

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!