Bisexual Pride

I can’t tell you how many times I’ve made a commit only to realize I forgot to add a change. I used to make another commit in order to fix it, until I learned how to amend my last commit. Today, I’ll show you how.

Stage your changes

The first thing you’ll want to do is stage your changes. You can do this by running the git add command in the console. You append it with the file(s) you want to add. For example, git add index.html.

Get the message from your last commit

Since you’re amending a commit—not creating a new one—you’ll probably want to use the same message. To retrieve it, run git log in the console, highlight the message, then copy it. Then press the Q key to exit the log.

Use the --amend flag

Now you just need to commit your changes. The trick is to use the --amend flag. The final command will look something like this:

git commit --amend --message "My lovely commit message"

And voilà! You’ve amended your last commit.