You are here
Home > GitHub > Amending The Most Recent Commit Message In Git

Amending The Most Recent Commit Message In Git

Ever made a typo in your git commit message? Or have you forgot to mention an important detail in the commit message? Correcting a commit message in Git can be very easy – if it’s the very last commit you want to edit!

Amending the Last Commit

To change the last commit message, you can simply commit again, using the –amend flag:

Easily said, this overwrites your last commit with a new one. This also means that you’re not limited to just editing the commit’s message: you could also add another couple of changes you forgot.

However, you need to keep the following important details in mind:

  • Amend only works with the very last commit. If you notice your mistake only after adding another commit, amend won’t help you much.
  • Amend rewrites the commit history in your repository: the old commit is replaced by a completely new one (a new and different commit object). This makes it very important that you don’t amend (= rewrite) commits that you’ve already published to a remote repository! Because in that case, your colleagues might have already based their work on this commit – which you would try to replace using “amend”.

Changing Older Commits

Also, if you want to change your older commits, GitHub has a tool for this use case:

The “interactive rebase” command, however, is quite an advanced tool: very powerful and quite dangerous. You should definitely understand what you’re doing before applying it! See here if you really need to use it.

The mode of action, however, is the same as with the –amend flag: you are rewriting history! Therefore, just as with amend, you should not use interactive rebasing on commits you have already pushed!