git add myfile.txt
git commit --amend --no-edit
Use interactive rebase:
git stash
git rebase -i [commithash]^
pick to edit. Then close the file.# pop the stash if the file is not untracked
git stash pop
# add the file
git add myfile.txt
# if other files were in the stash, stash them again
git stash
# amend the commit
git commit --amend --no-edit
git rebase --continue
While trying to add several files to different commits, it might get errors when amending the commits.
To fix it, try adding the file one by one (one rebase each time), starting with the most recent commit to modify.