2
votes

emacs does not create backups of files inside a git repository. I would like to have them saved, since I often rely on them for undoing some changes before committing my changes to the git repo.

I was using xemacs until recently, and it would always create the usual *~ files at first save. But emacs doesn't do it if working inside a git project: it makes the usual backup files, when working outside the project, but not the ones inside a git repo.

I tried the following in my .emacs file without success:

(setq make-backup-files t)
(setq backup-inhibited nil)

I have looked at the doc here:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Making-Backups.html

and in the section about backup-inhibited it seems as if emacs checks each time if the file is controlled by a control version system, and in case it is, it wouldn't create the backup file. This check might be the one preventing the creation of the desired backup file. Is there a way to change this behavior?

1

1 Answers

3
votes

As seen here

if your files are under version control, then vc-checkin sets backup-inhibited to t.

It also mentions completion-ignored-extensions, but check first if you have that module activated, as in this thread: the lisp/vc.el.
That module does include:

   ;; (unless vc-make-backup-files
   ;;   (make-local-variable 'backup-inhibited)
   ;;   (setq backup-inhibited t))

Setting vc-make-backup-files could help.

The "Backup Files" chapter does explain:

For files managed by a version control system (see Version Control), the variable vc-make-backup-files determines whether to make backup files.
By default it is nil, since backup files are redundant when you store all the previous versions in a version control system