Content-Type: text/shitpost


Subject: Gitignore patterns
Path: you​!your-host​!ultron​!the-matrix​!mechanical-turk​!berserker​!plovergw​!shitpost​!mjd
Date: 2018-02-01T11:27:09
Newsgroup: talk.mjd.gitignore
Message-ID: <1901d346dd8bba5b@shitpost.plover.com>
Content-Type: text/shitpost

Emacs left behind an auto-save file, c/#computer-wizardry.blog#, and every time I did git status -s I saw it mentioned. So I wanted to tell Git to ignore this sort of file. (Sure, I could just remove the file, but that's not the point.)

Git has a mechanism for telling it that certain files are uninterresting and should never be tracked. You put patterns into .git/info/exclude, and files whose names match the patterns are ignored. I wanted to exclude all files whose names begin and and with a # sign, so I put in:

    #.*#

but this didn't work. I did cat .git/info/exclude and the line wasn't there. “Wat” I said, and went to edit the file, and there it was. I then realized that the default .git/info/exclude starts with a big comment explaining how it works, that the comment lines all start with #, that my new line also starts with #, so it is a comment, so Git was ignoring it, and also I was ignoring it when I did cat to view the file, and that's why I thought it wasn't there at all. Sheesh.

So I escaped the # signs:

    \#.*\#

and that also didn't work. Then I got out the manual and found that you only need to escape a # sign at the start of a line, so I changed it to:

    \#.*#

and it still didn't work. At that point I gave up and moved on to doing something else.

Today I came back to it. I thought that a straight-up filename was matched by any file with that name in any subdirectory, but maybe I had that wrong, so I tried

    */#.*#

which ought to work at least for files one level down, but it didn't. Then I consulted the manual again and found that ** will match any sequence of directories, so I tried

    **/#.*#

and that didn't work either. Then I tinkered with backslashing the # signs various ways but nothing fixed the problem.

The problem was that I was using regex syntax .* instead of glob syntax *. The right answer is:

    \#*#

Just to be clear, this was not a problem with Git. It was a problem with me. Some days it pays to just stay in bed.

Sheesh.