If your project is under Git , and you committed your last version to Git , you can revert to last version.
Else, if you have Time Capsule and you enabled it, you can revert to older time of the document.
Last, if you have none of the above and you have no luck with Cmd + Z , then you have to rewrite it.