How to amend your most recent commit message on your local repo from the command line – 073

Following yesterday’s tip where you learned how not to panic when presented with a vi editor, today’s tip will cover the scenario of what if you wanted to amend your most recent commit message.

Suppose you had a git commit message “updating readmeee” which you’ve caught immediately. The most straightforward way is git commit -m “new message” –amend

git commit -m "updating readme" --amend updating last commit message

But let’s say you forgot the message flag and now you’re now face-to-face with the vi editor.

DO NOT START IMMEDIATELY TYPING! IT’S A TRAP!

star wars it's a trap meme

When vi first opens, your cursor will be in command mode, despite seeing the cursor in the editor. (pssst… it’s a trap)

image_thumb[12]

You’ll want to press The status bar at the bottom will change to show —Insert–

SNAGHTML717cfa_thumb[2]

Once you are finished with your edits, hit ESC to enter Command Mode, and then press :wq for write and quit.

and voila, you’ll see in your log that your last commit message has been modified, but the timestamp (and rest of commit history) is still the same.

image_thumb[21]

One thought on “How to amend your most recent commit message on your local repo from the command line – 073

Leave a comment