Skip to main content

How to change your last commit

· One min read
Matej Jelluš
Tech leader and IT nerd who is constantly trying new things, sharing his experiences and still enjoys writing code in his free time. Currently looking for new challenges and opportunities.

You commited something and right after that you saw you forgot to remove log or add another file? Or you just want to extend your message? It is not necessary to revert the commit everytime.

How to add file to the last commit

You did some changes, added files and commited. Then you saw you forgot to add another file. What to do?

git add <the file>
git commit --amend --no-edit

The --no-edit option just uses the original commit message without changing it or without launching an editor.

How to change commit message for the last commit

You commited something and you forgot to add an important note into the commit message? Or you want to add issue number? No problem...

git commit --amend

It will open your editor and let you change the message. Of course you can use -m option:

git commit --amend -m "commit message"

Warning

Do not use ammend if you have already pushed the commit to the repo and someone pulled it. This could, or better - probably will, cause problems.


Do you like this post? Is it helpful? I am always learning and trying new technologies, processes and approaches. When I struggle with something and finally manage to solve it, I share my experience. If you want to support me, please use button below. If you have any questions or comments, please reach me via email juffalow@juffalow.com.

I am also available as a mentor if you need help with your architecture, engineering team or if you are looking for an experienced person to validate your thoughts.