Previous: , Up: Backup Files   [Contents][Index]

20.3.2.3 Copying vs. Renaming

Backup files can be made by copying the old file or by renaming it. This makes a difference when the old file has multiple names (hard links). If the old file is renamed into the backup file, then the alternate names become names for the backup file. If the old file is copied instead, then the alternate names remain names for the file that you are editing, and the contents accessed by those names will be the new contents.

The method of making a backup file may also affect the file’s owner and group. If copying is used, these do not change. If renaming is used, you become the file’s owner, and the file’s group becomes the default (different operating systems have different defaults for the group).

The choice of renaming or copying is made as follows:

When a file is managed with a version control system (see Version Control), Emacs does not normally make backups in the usual way for that file. But committing (a.k.a. checking in, see Concepts of Version Control) new versions of files is similar in some ways to making backups. One unfortunate similarity is that these operations typically break hard links, disconnecting the file name you visited from any alternate names for the same file. This has nothing to do with Emacs—the version control system does it.

Some file storage services support file versioning: they record history of previous versions of files, and allow reverting to those previous versions. If you want to be able to do that with files hosted by those services when editing them with Emacs, customize backup-by-copying to a non-nil value.

Copying the old file for backup is also useful when editing precious files, because it makes sure the old file keeps its name if something fails between the backup and the saving of your edits. Alternatively, you can customize file-precious-flag to a non-nil value, which implies backups by copying and also protects against I/O errors while saving your edits.

Previous: Automatic Deletion of Backups, Up: Backup Files   [Contents][Index]