So you just committed some code only to realize you had a few files missing from your commit, which you forgot to add. This happens a lot in everyday coding and git has an easy fix for that. If you are like me, you have done something like resetting the head to the commit before last commit and then committing files again but that’s a hack and it’s avoidable. How? Keep reading.
Use git add -u
or git add .
to stage the new changes or add any missing files.
And then for updating the last commit with newly added / staged files use --amend
argument.
git commit --amend
If you just want to update the commit message, use -m
option for adding a commit message. If you don’t specify it, you will be prompted with the previous commit message as a default, in a standard vim mode.
For someone new to vim: You could use escape key to get out of editing mode with wq
which edits and saves your commit
When you’re done you can check git log --stat
to see your amended commit with the extra changes.
For documentation, check out Git’s ‘commit –amend’ documentation.