Edit Your Last Git Commit Message With --amend

A typical scenario you might come across while using Git is the need to change a commit message after it's been committed.

But don't worry!

Git has you covered with the --amend command.

Amend your last commit message

If you want to alter your most recent commit, you can just run git commit --amend. This will bring up the editor in your terminal where you update your message.

And to make it even easier, we can pass the updated message:

git commit --amend -m "updated commit message"

Don't amend shared code

When you amend your commits, it is an entirely new one, so your previous one will no longer exist. If someone else is using code with your commit will mean the history is out of sync and can be challenging to fix.

So try to only amend code before you've pushed it to a shared branch since the headache an amend can cause usually isn't worth the nice commit message.


Follow me on Twitter or connect on LinkedIn.

🚨 Want to make friends and learn from peers? You can join our free web developer community here. 🎉

Git
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses: Lead Developer, Software Architect, Product Manager, CTO, and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.