95

I want to add emacs autosave files to my .gitignore with the glob #*# but of course, lines starting with a hash are comment lines.

How can I get this into my .gitignore without it being treated as a comment?

jlf
  • 3,461
  • 2
  • 18
  • 14
Steve Folly
  • 8,327
  • 9
  • 52
  • 63

4 Answers4

128

Did you try

\#*#

Or:

\#*\#

Since 1.6.2, \ should be supported in .gitignore (see this patch)

To be precise, 1.6.2.1 (March 2009)

.gitignore learned to handle backslash as a quoting mechanism for comment introduction character "#".

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
33

Another way of escaping # is to use the character set syntax, so that your #*# glob becomes

 [#]*[#] 

in your .gitignore file.

Charles Stewart
  • 11,661
  • 4
  • 46
  • 85
8

This doesn't exactly answer your question, but I think it may solve more problems than just this one symptom:

You can move the autosave and backup files into a completely different directory so that your source directories don't get cluttered.

Ryan Fox
  • 10,103
  • 5
  • 38
  • 48
8

This worked for me.

*[#]*[#]
*[#]*

@CharlesStewart was close but did not work for sub-directory files which had autosave generated files.

cevaris
  • 5,671
  • 2
  • 49
  • 34