Skip to content

Try our new Crash Courses!

Become a member using the button below to hide this banner and gain access to our new Crash Courses.

Edit your last commit – Git

Summary

To edit your last commit, enter the following command in your terminal:

git commit --amend

Details

The above command to be used to edit the last commit message, or add files to the last commit and edit the last commit message.

If no changes have been made since the last commit and you just want to edit the last commit message, simply enter the above command in your terminal. The command will open up an editor in your terminal with the last commit message. Press i to enter INSERT mode, which allows you to edit the commit message. When you’re done editing the message, press ESC. Then, press :wq to save your message and exit the editor.

If you want to add files to your last commit, use the staging command (git add) first to add your missing files. Then follow the procedure from above.

Exercises

First, add some code to index.html. Then stage the changes using git add .. Then commit the changes. Then try editing the last commit.

git add index.html

git commit -m "My commit message"

git commit --amend -m "New commit message"

References

Undoing Things from the Pro Git book

Back to: Git Reference > Git Undoing Things