# for the most recent commit
git commit --amend -m "changed commits"
git push -f
# for n older commits
git rebase -i HEAD~n
# follow instuctions e.g. use r for reword to edit older commits
# removing a line means THAT COMMIT WILL BE LOST.
git rebase --continue
# solve conflicts if exist
git push -f
# git push --force-with-lease origin <branch> is safer
git checkout branch_name
git commit --amend -m "Modified message"
# if previous commit is not pushed yet
git push
# or if previous comment was pushed in a previous commit:
git push --force-with-lease branch_name
git rebase -i @~9 # Show the last 9 commits in a text editor
# Here you can change the one you want to change from `pick` to `e` or `edit`
# After that you can either ammend it to change the message:
git commit --amend # or you can reset the changes and commit it again: `git reset @~`
# When all the changes are made, rebase it
git rebase --continue
git rebase -i HEAD~4
pick e459d80 Do xyz
pick 0459045 Do something
pick 90fdeab Do something else
pick facecaf Do abc
#Now replace pick with reword for the commits
# you want to edit the messages of
pick e459d80 Do xyz
reword 0459045 Do something
reword 90fdeab Do something else
pick facecaf Do abc
# Exit the editor after saving the file,
# and next you will be prompted to edit the messages
# for the commits you had marked reword, in one file per message.
#Source https://stackoverflow.com/a/45302710/11266661