I’m sure that once in a while, it just happens that you made a mistake. That’s ok. It happens.
But what if you commit the mistake. Several times. A headache for sure and so many other horrible things as well.
For those cases, I really recommend giving a read to On undoing, fixing, or removing commits in git. A document made by Seth Robertson.
It contains lot of resources for very incredible situations. I read it sometimes and it helps me out many others.
More at my technical blog