We can revert (means delete the bad commits) to the previous working commit. You can do this by the following two commands:
git reset --hard [previous working Commit SHA id here]git push origin [branch Name] -f
It will remove your previous Git commits.
If you want to keep your changes, you can also use:
git reset --soft [previous Commit SHA id here]
Then it will save your changes.