Change a Commit Message that Hasn't Been Pushed Yet

Chris Achard
InstructorChris Achard
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

If you make a mistake in a commit message but HAVEN'T pushed it yet, you can change that commit message with --amend:

git commit --amend -m "New message"

This won't change any of the files in your commit - but will rewrite the commit with the new message.

Instructor: [0:00] Let's start a new git project by going to New on GitHub and entering a repository name of git_mistakes. I'll make that public and initialize it with a README.

[0:14] Once it's created, I can find the clone link and in a terminal I will git clone that repository. Then I can cd into it. I'm going to touch index.html, which'll be the first file that we make. In a text editor, we can open that folder.

[0:35] In our index.html file, let's paste in some HTML. Now we want to add this to a commit. First, let's do a git status to see that we have index.html that is not tracked yet. It's untracked. We can add index.html. Now if we do a git status, we have it as changes to be committed.

[0:56] This is what we call staged or in the index. We can commit that with git commit -m. We'll say adding index.html to git mistooks.

[1:08] As soon as I type that, I realize that I said mistooks instead of mistakes, so I want to change that commit message. Since I haven't pushed this yet, I can just say git commit --ammend. Now I can say that I want to give it a new message of adding index.html to git mistakes.

[1:30] If I do a git log --oneline, I can see I have my initial commit that GitHub made when it made the project, and then I have my adding index.html to git mistakes. It actually rewrote the commit message that had a typo in it.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today