• Edit the commit locally first
  • If the commit you want to edit isn’t the last one, you need to use the command git rebase -i interactive rebase.
  • git rebase -i HEAD~n if you want to go back N commits.
  • In the file that opens, I replace pick with edit next to the commit I want to edit, then save and close the file.

Once you’ve finished editing the file:

git add <file>
git commit --amend

Once you’ve finished editing the commit, you need to continue the rebase:

git rebase --continue

And push the changes:

git push --force-with-lease

Warn

—force-with-lease force push only if the remote branch has not been updated since it was cloned or fetched