shellstreak

Change the last commit message

Careful: rewrites history

Short answer

Run git commit --amend -m "The right message". The last commit is replaced by one with the new message and the same changes.

Amending makes a new commit that replaces the old one. Fine before you push; after a push it rewrites shared history, so leave the message as it is.

The commands, one by one

  1. 1git commit --amend -m "Add muffin recipe"

    Replaces the latest commit with a copy that has the new message. Nothing that's staged right now is lost: if something is staged, it goes into the amended commit too.

For your own repository: Put your own message between the quotes.

Try it safely

You committed with the message Add muffn recipe.

learner@shellstreak: ~
Starting your practice shell…

Type your own commands too. Reset puts the repository back to just after the mistake.

Practise this in 5 minutes

Lesson 62, Commits a reviewer can read, walks you through this undo and the ones around it in a safe terminal, step by step, and checks your answers.

Keep the terminal cheat sheet handy: free to print

Get the shellstreak newsletter

Short terminal and Git tips you can try in a minute, plus a heads-up when new free tools and lessons ship. It lands now and then, never a flood.

No spam, unsubscribe in one click.