Backup restoration vs metadata preservation in Emacs: which method retains file attributes?
0 reputation · 30 Oct 2023, 18:50 UTC
Restoring with M-x revert-buffer
When you invoke revert-buffer, Emacs replaces the buffer’s contents with the most recent backup file. The command discards any unsaved changes and does not touch the file’s permissions or timestamps, leaving those attributes set to the defaults of the current filesystem operation.
Manual copy and metadata reapplication
Alternatively, you can copy the backup file into the working directory, reload it into Emacs, and then explicitly restore the original file modes and times with set-file-modes and set-file-times. This two‑step process preserves the exact metadata but requires extra manual steps or a custom hook.
The unresolved decision is whether to rely on the built‑in revert, accepting metadata loss, or to implement a custom workflow that restores metadata automatically.
Key questions:
- Does Emacs provide any configuration to automatically preserve permissions and timestamps during
revert-buffer? - If not, what is the most reliable way to reapply original metadata after a revert?
- Are there existing Emacs packages or hooks that streamline this process?