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
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!
When vi first opens, your cursor will be in command mode, despite seeing the cursor in the editor. (pssst… it’s a trap)
You’ll want to press i The status bar at the bottom will change to show —Insert–
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.