You actually did the right thing by reverting the commits after publishing them to the repository. Because you already pushed the commits, there generally exists the possibility that someone else has already pulled your unwanted commit (and maybe the revert commit too).
You could use git reset --hard HEAD~2
, but don't do that. The reason for not doing this is that deleting commits effectively rewrites history. This means that anyone sharing this branch could have problems next time they go to pull. By undoing the commit via a git revert
, you guarantee that no one else will have problems.