If you're like most people, you often spend a few hours editing a file, only to decide that you liked your original version better. Or you press some strange sequence of keys that makes Emacs do something extremely weird and that you can't "undo." Emacs provides several ways to get out of these tight spots.
First, try the command
Before deciding what to do, it's important to understand the
difference between these two questions. Emacs creates an auto-save
file every 300 keystrokes you type. So, if you're reverting to the
auto-save file, you'll at most lose your last 300 keystrokes. Maybe
this is what you want - but maybe you made the mistake a long time ago.
In that case, you don't want to use the auto-save file; type
It's possible that you'll only see the second question ("Revert buffer from file..."). This means that you have saved the file sometime within the last 300 keystrokes. As soon as you save a file, Emacs deletes the auto-save file. It will create a new one every 300 keystrokes.
It's worth noting that Emacs is very
picky about what you type.
If it asks for a
If you're in real trouble, and you want to go back to your original file - the way it was when you started editing - you need to recover Emacs' backup file . If you're editing a file that already exists, Emacs will create a backup file as soon as it starts. If you're editing a new file, Emacs will create a backup the second time you save the file. Once it's created, the backup file is never touched; it stays there until the next time you start Emacs, at which point you'll get a new backup, reflecting the file's contents at the start of your editing session.
Now that we're over the preliminaries, how do you recover the backup
file? Emacs doesn't have any special
command for doing this; you have to do it by hand. The backup file's
name is the same as your original filename, with a tilde (
Note that Emacs has the ability to save "numbered" backup files, like the VAX/VMS operating system. We've never played with this feature and don't particularly think it's a good idea. But it's there if you want it.