emacs 不备份 git 存储库中的文件

emacs does not backup files in git repo

emacs 不会在 git 存储库中创建文件备份。我想保存它们,因为在将我的更改提交到 git 存储库之前,我经常依赖它们撤消一些更改。

我一直在使用 xemacs 直到最近,它总是会在第一次保存时创建通常的 *~ 文件。但是如果在 git 项目中工作,emacs 不会这样做:在项目外部工作时,它会生成通常的备份文件,但不是 git 存储库中的那些。

我在 .emacs 文件中尝试了以下操作但没有成功:

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

我看过这里的文档:

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

并且在关于 backup-inhibited 的部分中,似乎 emacs 每次都检查文件是否由控制版本系统控制,如果是,它不会创建备份文件。此检查可能是阻止创建所需备份文件的检查。有没有办法改变这种行为?

作为seen here

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

它也提到了 completion-ignored-extensions,但首先检查您是否激活了该模块,如 in this thread: the lisp/vc.el
该模块 does include:

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

设置 vc-make-backup-files 可能会有帮助。

Backup Files”一章确实解释了:

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