Git FAQ

Frequently asked questions around Git and Version Control.

How can I edit / fix the last commit's message?

Made a typo in your commit message? Or forgot to mention an important detail in the message? Correcting a commit message in Git can be very easy - if it's the very last commit you want to edit!

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!

Amending the Last Commit

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

$ git commit --amend -m "New and correct message"

Simply put, 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.

$ git add another/changed/file.txt
$ git commit --amend -m "message"

However, keep two important details in mind:

  1. Amend only works with the very last commit. If you notice your mistake only after adding another commit, amend won't help you much.
  2. 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".

Therefore, use "amend" whenever you want to change / edit your very last and unpushed commit.

In case you are using the Tower Git client, amending your last commit is easily possible right from the commit area interface:

Changing Older Commits

If you want to change older commits, Git also has a tool for this use case:

$ git rebase --interactive

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

If you want easy access to advanced Git tools like "interactive rebase", the Tower Git client can be helpful. For example, you can simply right-click the commit you want to change and select "Edit Commit Message". In the background, an Interactive Rebase session is performed to make this possible:

No matter if you're using "Interactive Rebase" from the Command Line or via Tower, the mode of action 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!


Learn More

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.