How to change your last commit

Published:

git

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.

Git commands that you might need sometime titleee

Git is something that most of us use daily, though there are functions / commands you do not use but still may help in some situations.

Read more
Write good git commit message titleee

For a long time I didn't know that even writing commit message can have its own "best practices". When I got in touch with git for the first time, this part was described with words like "...and here you can write something short about what's going on in the commit".

Read more