How do I ignore file extensions in git regardless

2019-02-05 16:04发布

I want to tell git to ignore e.g. jpg files regardless of how the extension is written.

e.g.

*.jpg

should ignore

.jpg, .JPG., .Jpg

etc.

Is that possible without telling git to ignore case altogether?

标签: git gitignore
2条回答
Bombasti
2楼-- · 2019-02-05 16:39

Git ignore understands glob pattern, so you can use this

*.[jJ][pP][gG]
查看更多
女痞
3楼-- · 2019-02-05 16:47

You can tell git to ignore case in most situations, including in your .gitignore files. All you need is:

git config core.ignorecase true

From a practical point of view, there may be trade-offs involved. The git-config(1) man page says:

   core.ignorecase
       If true, this option enables various workarounds to enable git to
       work better on filesystems that are not case sensitive, like FAT.
       For example, if a directory listing finds "makefile" when git
       expects "Makefile", git will assume it is really the same file, and
       continue to remember it as "Makefile".

       The default is false, except git-clone(1) or git-init(1) will probe
       and set core.ignorecase true if appropriate when the repository is
       created.

So, you may run into trouble if you are on a case-sensitive filesystem. Your mileage may vary.

查看更多
登录 后发表回答