Preferred to use over reset if commits have been pushed to remote as does not remove commit history but rather creates a new commit.

[undo the changes of the last commit]

git revert HEAD

[undo the changes of the specified commit. Only changes made in the single commit will be undone not those of subsequent commits]

git revert <commit-id>

https://www.atlassian.com/git/tutorials/undoing-changes/git-revert#:~:text=It%27s%20important%20to%20understand%20that,a%20reset%2C%20not%20a%20revert.