It can be a huge pain to find that your commit is just a bit off, or you put a typo in the commit message. Luckily, git can help!
Simply make and stage your change as normal, and then when you want to commit your changes, instead of git commit
, run:
git commit --amend
git will pop up your default editor and allow you to edit your last commit with your new changes. You'll also be able to change the commit message easily from the editor, if you want to.
Note: This operation does involve the changing of history, so if you had already pushed your commit to a remote repository, you will need to force-push your amended commit:
git push --force
As always with force-pushes, be careful that you are doing what you mean to.