【问题标题】:How do I ignore file extensions in git regardless of case?无论大小写如何,我如何忽略 git 中的文件扩展名?
【发布时间】:2012-06-22 10:00:51
【问题描述】:

我想告诉 git 忽略例如jpg 文件,无论扩展名是如何编写的。

例如

*.jpg

应该忽略

.jpg、.JPG.、.JPG

等等

如果不告诉 git 完全忽略大小写,这可能吗?

【问题讨论】:

  • 你想让 git 在不区分大小写的文件系统上“工作”,还是只是为了忽略目的?

标签: git gitignore


【解决方案1】:

您可以告诉 git 在大多数情况下忽略大小写,包括在您的 .gitignore 文件中。您只需要:

git config core.ignorecase true

从实际的角度来看,可能需要权衡取舍。 git-config(1) 手册页说:

   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.

因此,如果您使用区分大小写的文件系统,您可能会遇到麻烦。您的里程可能会有所不同。

【讨论】:

  • 我不会推荐这个。首先,正如您所说,这不仅使.gitconfig 不区分大小写,而且基本上所有Git。然后,配置是每个用户或每个克隆的东西,因此它不适用于与您共享 .gitconfig 的其他共同开发者。
  • 我同意@MatthieuMoy。您绝对、肯定、最肯定会为此感到遗憾——但只有在调试了数小时后,您的文件为何丢失或为什么一切都被神秘地破坏了。如果此功能已开启,请将其关闭。
  • 我用的是win10,好像不区分大小写。我不记得在我的仓库中设置 core.ignorecase。我可以检查谁?
  • 正如@MatthieuMoy 指出的那样,这通常不安全,但只有当我们有不区分大小写的文件系统时,例如在Windows 上。
  • NTFS 区分大小写。窗户不是。这是一个微妙的区别。此选项适用于 FAT16,它既不区分大小写也不保留大小写。恕我直言,这是错误的方法
【解决方案2】:

Git ignore 理解 glob 模式,所以你可以使用这个

*.[jJ][pP][gG]

【讨论】:

    猜你喜欢
    • 2012-12-20
    • 2023-03-30
    • 2013-05-07
    • 2014-05-17
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    相关资源
    最近更新 更多