I'm trying to .gitignore emacs temporary/autosave files. I'm using...
\.\#.*
in my .gitignore.
But git add -A
run in a subfolder is still giving me:
# new file: .#make_collections.py
# new file: .#norm_collections.py
# new file: make_collections.py
# new file: norm_collections.py
even though
\.\#.*
is clearly getting the right file names and not the wrong ones when I test it with a regex tester.
gitignore doesn't use regular expressions. Instead it uses shell glob patters. The man page tells you two things important for this situation:
and
This means that the pattern you want to use is simply
.#*
.Now the second pattern that matov mentioned,
#*
, doesn't do anything as it is treated as a comment by git. Hence me quoting that second sentence from the man page.Emacs autosave files are ignored with
If you want an easy way to ignore files, you can also use http://www.gitignore.io which helps create useful .gitignore files for your project.
Here is the emacs template: https://www.gitignore.io/api/emacs
There is also documentation demonstrating how to run
gi
from the command line.files are ignored with:
\#*\# .\#*
You can also instruct emacs to save the autosave files in a different directory altogether by setting the variable
auto-save-file-name-transforms
, I have this in my init fileThis instructs emacs to store the auto-saves inside the
auto-save
folder in the user-emacs-directory (usually~/.emacs.d
).To save backup files in a different directory set the variable
backup-directory-alist
, the following will save backup files insidebackups
folder in the user-emacs-directory