Let's say I check out a file from a library on a site, make changes, and then by mistake I do undo the check-out and discard changes. Is there a way to recover the discarded changes?
No, there is no way to recover that. The information is not stored in the version history until you check in a minor change. If you tell it to discard your changes and didn't check in a minor change at some point, your changes are lost.