.gitignore正则表达式为emacs临时文件

Mit*_*ops 18 regex git emacs gitignore

我正在尝试.gitignore emacs临时/自动保存文件.我正在使用...

\.\#.*
Run Code Online (Sandbox Code Playgroud)

在我的.gitignore中.

但是git add -A在子文件夹中运行仍然给了我:

#       new file:   .#make_collections.py
#       new file:   .#norm_collections.py
#       new file:   make_collections.py
#       new file:   norm_collections.py
Run Code Online (Sandbox Code Playgroud)

即使

\.\#.*
Run Code Online (Sandbox Code Playgroud)

当我用正则表达式测试器测试它时,显然得到了正确的文件名,而不是错误的文件名.

小智 28

你也可以通过设置变量来指示emacs将自动保存文件完全保存在不同的目录中auto-save-file-name-transforms,我在我的init文件中有这个

(setq auto-save-file-name-transforms
          `((".*" ,(concat user-emacs-directory "auto-save/") t))) 
Run Code Online (Sandbox Code Playgroud)

这指示emacs将auto-save文件夹中的自动保存存储在user-emacs-directory(通常~/.emacs.d)中.

要将备份文件保存在不同的目录中设置变量backup-directory-alist,以下内容将保存backupsuser-emacs-directory目录下的文件夹中的备份文件

(setq backup-directory-alist
      `(("." . ,(expand-file-name
                 (concat user-emacs-directory "backups")))))
Run Code Online (Sandbox Code Playgroud)


Mor*_*kus 21

gitignore不使用正则表达式.相反,它使用shell glob模式.该手册页告诉你两两件事很重要的这种情况:

Otherwise, Git treats the pattern as a shell glob suitable for
consumption by fnmatch(3) with the FNM_PATHNAME flag.
Run Code Online (Sandbox Code Playgroud)

A line starting with # serves as a comment. Put a backslash ("\")
in front of the first hash for patterns that begin with a hash.
Run Code Online (Sandbox Code Playgroud)

这意味着您想要使用的模式很简单.#*.

现在,matov提到的第二种模式,#*没有做任何事情,因为它被git视为评论.因此,我引用了手册页中的第二句话.


Özg*_*ğlu 9

Emacs自动保存文件将被忽略

\#*#
Run Code Online (Sandbox Code Playgroud)

  • 你试过这个[#]*[#] (3认同)
  • .[#]*[#]我用我的gitignore文件尝试了这个,它正在运行. (2认同)

Ped*_*Luz 5

文件被忽略:

\#*\# .\#*