If you need to switch temporarily to a committed branch
$git checkout <commit-id>
commit id will be available in
$git log
and it should be the id of the commit that you need to revert. If you need to make commits, go ahead and make a new branch
$ git checkout -b <old-state> <commit-id> (ie ;- $git checkout -b master <commit-id>)
To go back, you just check out the branch that you were on again. (If you've made changes, when switching branches, you'll have to deal with them as appropriate. You could reset to throw them away, you could commit them to a branch there if you want a branch there.)
HARD DELETE FOR UNPUBLISHED COMMITS
If you need to reset all mess that you have created during revert use
$git reset --hard <commit-id>
Do only if you have committed the work that you need further. Also, you can stash, pop if there is a work to save
This saves the modification, then re-applies that patch after resetting. If you already published the commits then you need to undo the published commits with new commits.
Undoing published commits can be done by using revert command.
$git revert <commit-id>
you can give the reverted commits by giving ranges.
$git revert HEAD~2...HEAD.
Reverting a merge commit
$git revert -m 1 <merge_commit>
You can get your index and work tree into the desired state, without changing HEAD
$git checkout 0d1d7fc32 .(commit-id)
then finally commit using $ git commit, thus, you can undo published commits.