Linux (like other unices) doesn't natively provide an undo feature. The philosophy is that if it's gone, it's gone. If it was important, it should have been backed up.
There is a fuse filesystem that automatically keeps copies of old versions: copyfs. Of course, that can use a lot of resources. Unfortunately, it's unmaintained. Gitfs might be an alternative, I've never tried it.
The best way to protect against such accidents is to use a version control system (cvs, bazaar, darcs, git, mercurial, subversion, ...). It takes a little time to learn, but it pays off awesomely in the medium and long term.