How to delete previos commit and add new commit to the same file with different commit message
If you just want to modify the most recent commit.
git reset --soft HEAD~1
This command moves the HEAD back by one commit, keeping the changes in your working directory.
Make any additional changes to the file as needed.
Add the file to the staging area:
git add <filename>
Then you can commit and push.
If all you need to do is change the commit message of the latest commit and you haven’t pushed it, then
git commit --amend -m "New commit message."