To revert a Git repository to a previous commit in two ways, one is Temporarily switch to a different commit and another one is Hard delete unpublished commits.

git revert <commit-hash>

Alternatively, you can use the git reset command followed by the commit hash to revert to a previous commit and discard commits made after it. This is a more dangerous option because it permanently removes commits, so make sure you really want to throw away the commits before using it.
git reset <commit-hash>

It's generally a good idea to create a new branch before reverting to a previous commit, so that you can easily switch back to the original branch if needed.

git branch new_branch
git checkout new_branch
git revert <commit-hash>