You can revert any commit, not just the last one, by passing a commit hash.
git revert followed by the commit hash writes the inverse operations and opens a commit message for you. History stays intact.
Want the full write-up with examples? I covered it here: How to undo changes in a Git repository using git revert
Follow along for more git tips like this!