4

Is there a command for recover the current file from the backup ?

I have a file ~/temp.txt and some backup files !home!djangoliv!temp.txt.~1~ ... !home!djangoliv!temp.txt.~5~, !home!djangoliv!temp.txt.~6~.

I would like to load backup files from the newer version to the older one (like git-time-machine for exemple)

Here my backup configuration

  (setq auto-save-default nil)
  (setq backup-directory-alist '(("." . "~/.emacs-backup-files/")))
  (setq version-control t       
        vc-make-backup-files t  
        backup-by-copying t     
        delete-old-versions -1) 
Dan
  • 32,584
  • 6
  • 98
  • 168
djangoliv
  • 3,169
  • 16
  • 31

2 Answers2

6

Le Wang's backup-walker library facilitates this:

traverse incremental diffs between backup versions

  • open backup in traversal mode if the diff seems interesting

traverse backups

  • Once a backup is opened, traversing amongst backups is easy using the same keys.
  • the point kept the same as much as possible while traversing backups as much as possible by parsing diff output on the fly.

blame

  • find the version of backup where a line disappeared. Of course this works best if you have comprehensive backup history.

cleanup

  • optionally kill all open backups when quiting
phils
  • 48,657
  • 3
  • 76
  • 115
2

How about this:

(defun revert-to-backup ()
  "Reverts to the latest backup file associated with the current buffer."
  (interactive)
  (let ((file (buffer-file-name)))
    (when file
      (let ((bak (file-newest-backup (buffer-file-name))))
        (if bak
            (progn
              (delete-region (point-min) (point-max))
              (insert-file-contents bak))
          (message "No backups found!"))))))

With this command you can revert the current buffer to its latest backup. The revert is not saved automatically, I'm assuming you might want to at least look at the content before hitting C-x C-s to save.

glucas
  • 20,175
  • 1
  • 51
  • 83