gitignore 匹配字符重复

标签 git gitignore

我在 git 存储库中有一个目录,里面有一些文件,我们称它为 matchdir:

$ ls matchdir
2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
da39a3ee5e6b4b0d3255bfef95601890afd80709
file.py
someotherfile.txt

我想将匹配 40 个十六进制字符的文件添加到我的 .gitignore 文件中。类似 matchdir/[0-9a-f]{32} 的东西,但这似乎不起作用。有什么方法可以匹配 .gitignore 文件中字符的特定重复次数?

最佳答案

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

将匹配所有恰好包含 40 个字母的文件。这不仅是十六进制字母,而且比匹配任何长度的 matchdir/* 都要好。在 emacs 下键入 40 ? 只需敲击 3 次:C-4C-0?

如果您只想捕获十六进制数字,现在可以轻松地用 [0-9a-f] 搜索和替换 ?:

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]

关于gitignore 匹配字符重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6726756/

相关文章:

添加到 .gitignore 后,git 仍然显示已修改的文件

git - .nyc_output 应该包含在 .gitignore 中吗?

git - 如何从 NetBeans IDE 8 和 Jenkins 重新连接到 GitLab 上的 git 存储库?

Java 无法运行程序 CreateProcess 错误=2

windows - 在 git bash for windows 中更改驱动器

gitignore - .gitignore - 忽略目录中除一个文件之外的所有内容

git - 尽管我的 .gitignore 为何我的配置文件仍被 checkin ?

android - 在 Android Studio 上连接到 GitLab 存储库

git - 控制 Go 包版本

eclipse - 用于 Eclipse 的 Gitignore