开发者

gitignore matching character repetitions

I have a directory in a git repository with some files in it, let's call it matchdir:

$ l开发者_运维技巧s matchdir
2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
da39a3ee5e6b4b0d3255bfef95601890afd80709
file.py
someotherfile.txt

I want to add the files that match 40 hex characters to my .gitignore file. Something like matchdir/[0-9a-f]{32} but that doesn't seem to work. Is there any way to match a specific number of repetitions of a character in a .gitignore file?


matchdir/????????????????????????????????????????

Will match all files with exactly 40 letters. That's not only hex letters, but it's better than matchdir/* that will match any length. Typing the 40 ? takes only 3 keystrokes under emacs: C-4C-0?.

It's now easy to search and replace ? by [0-9a-f] if you want to catch only hex numbers:

matchdir/[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]


Not an exact match, but if those are the only files without an extension and there are no subdirectories, a workaround might be this:

matchdir/*
!matchdir/*.*

Ignore all files, then unignore those with a dot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜