Skip to content

Try our new Crash Courses!

Buy one of our new Crash Courses, now hosted on Teachable.

Edit your last commit – Git


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

git commit --amend


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.


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"


Undoing Things from the Pro Git book

Back to: Git Reference > Git Undoing Things