Previous: Automatic Deletion of Backups, Up: Backup Files [Contents][Index]
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:
backup-by-copying
is non-nil
(the
default is nil
), use copying.
backup-by-copying-when-linked
is
non-nil
(the default is nil
), and the file has multiple
names, use copying.
backup-by-copying-when-mismatch
is
non-nil
(the default is t
), and renaming would change
the file’s owner or group, use copying.
If you change backup-by-copying-when-mismatch
to nil
,
Emacs checks the numeric user-id of the file’s owner and the numeric
group-id of the file’s group. If either is
no greater than backup-by-copying-when-privileged-mismatch
, then it
behaves as though backup-by-copying-when-mismatch
is
non-nil
anyway.
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]