简体   繁体   English

.gitignore中多个文件扩展名的简写

[英]Shorthand for multiple file extensions in.gitignore

Is there a Bash script-like shorthand for matching multiple different extensions in a .gitignore file such as: 是否有类似于Bash脚本的简写形式,用于匹配.gitignore文件中的多个不同扩展名,例如:

*.{bak,save,aux,nav,toc}

?

The syntax above definitely does not work. 上面肯定语法不起作用

Couldn't find answers online, so tried it out myself and this worked (creating a test local repository with SourceTree). 无法在线找到答案,因此自己尝试了一下,并且行得通(使用SourceTree创建测试本地存储库)。 This is editing the .gitignore file. 这正在编辑.gitignore文件。

*[.bak, .save, .aux,. * [。bak,.save,.aux。 nav, .toc] 导航,.toc]

spaces or no spaces in between the comma and full stop are ok too. 逗号和句号之间也可以有空格或没有空格。

So in my case I had to do this 所以就我而言,我必须这样做

Ignore all files in this directory, except for dll and dic files: 忽略此目录中的所有文件,但dll和dic文件除外:
Web.Site/Third-party Assemblies/* 网站/第三方程序集/ *
!Third-party Assemblies/**/*[.dll, .dic] !第三方程序集/**/*[.dll、.dic]

The method mentioned in the other answer, *[.bak, .save, .aux,. nav, .toc] 其他答案中提到的方法*[.bak, .save, .aux,. nav, .toc] *[.bak, .save, .aux,. nav, .toc] , does not work . *[.bak, .save, .aux,. nav, .toc] 无效 Or at least, not as expected. 或至少不像预期的那样。 It actually selects much more than just those extensions. 实际上,它选择的不仅仅是这些扩展。

As far as I can tell, there is no way to do this, unless the extensions you want to ignore are all a single character long. 据我所知,没有办法做到这一点,除非您要忽略的扩展名全都是单个字符。

According to Git's documentation : 根据Git的文档

" [] " matches one character in a selected range [] ”匹配选定范围内的一个字符

As can be seen in the example later on that page: 如该页面后面的示例所示:

 # ignore objects and archives, anywhere in the tree. *.[oa] 

This would ignore any .o or .a files. 这将忽略任何.o.a文件。

So this means that a pattern like *[.ext, .txt, .bin] will behave identically to *[beintx., ] (which is just the same pattern with duplicate characters removed and sorted) and will ignore any file ending in (including extension) any one of those nine characters. 因此,这意味着*[.ext, .txt, .bin]这样的模式与*[beintx., ]行为相同(这是相同的模式,删除并排序了重复的字符),并且将忽略 ( (包括扩展名)这9个字符中的任何一个。

I just tried this out on a Git repository of my own and it does indeed seem to follow this behavior. 我只是在自己的Git存储库上进行了尝试,确实确实遵循了这种行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM