Fixing the Last Commit

In this episode, we will learn how to correct our very last commit - e.g. because we've mistyped the commit message or forgot to add a change.

Transcript
Fixing the Last Commit

Correcting your last commit is quite a common case: you might have mistyped the commit message or forgot to add a change.

And as long as it’s the very last commit, Git makes this very easy. Let’s look an example case…

So, we should definitely get that commit message fixed. In the commit interface, you can use the “amend” checkbox. This automatically prefills the message fields with the last message. So you can easily edit and change.

Here we go: it seems as if we’d never made that typo!

Of course, you can also add any changes that you might have forgotten. Simply add them to the staging area - and then again use the amend feature. And you’ll see that "index.html" is now part of that commit - just as we intended to.

Using amend is incredibly easy and very practical. There’s only thing to remember: since it rewrites the commit history, you should use it only on commits that you haven’t pushed to a remote repository, yet.

Stick to this rule, and everything’s fine.