I usually meet this situation on some hot fixes days so I decided to take a note here in case I need to look for the solution again.
It happens to me a lot with the newly created files, untracked files, since they are not grouped with the changed files.
To add some files to the previous commit, do the following steps:
git add file1
git add file2
git commit --amend --no-edit
The --no-edit
flag allows to make an amendment to the commit without changing the commit message.
After that, if you already pushed the previous commit to the remote repository, your next push will get the error:
! [rejected] ... non fast-forward
To solve that, you will need to force the push:
git push origin <branch> --force
That’s it!