.gitignore regex for emacs temporary files

前端 未结 6 1631
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 06:11

I\'m trying to .gitignore emacs temporary/autosave files. I\'m using...

\\.\\#.*

in my .gitignore.

But git add -A run in

6条回答
  •  Happy的楠姐
    2021-02-05 06:52

    gitignore doesn't use regular expressions. Instead it uses shell glob patters. The man page tells you two things important for this situation:

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

    and

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

    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.

提交回复
热议问题