- 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~nif you want to go back N commits.- In the file that opens, I replace
pickwitheditnext 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 --amendOnce you’ve finished editing the commit, you need to continue the rebase:
git rebase --continueAnd push the changes:
git push --force-with-leaseWarn
—force-with-lease force push only if the remote branch has not been updated since it was cloned or fetched