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) 
  • There's diff-backup, from which you could then reverse apply the patch to recover, but that command always uses the latest backup file. – p_wiersig Dec 6 '16 at 14:26
  • Thanks, not the complete answer, but interesting – djangoliv Dec 6 '16 at 14:32
  • github.com/lewang/backup-walker ? – phils Dec 6 '16 at 21:49
  • @phis Thanks backup-walker do the tricks – djangoliv Dec 7 '16 at 12:20
  • I've now added that as an answer, as this question just got bumped. – phils Mar 6 '17 at 23:26
4

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
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.

  • Thanks, but I want to go through all the backups from the most recent to the oldest. – djangoliv Dec 7 '16 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.