Git ignorecase in Case-sensitive system

晚上10点多公司的妹子发了张截图给我(妹子这么刻苦让我汗颜。。。),在我们的 git 仓库中,存在几对仅文件名大小写有区别,内容完全一样的文件。原因很容易想到——重命名。这个问题比较小一般也不容易出现,不过其实花时间想想也蛮有意思。

case-insensitive file system

不同的文件系统对大小写是否敏感策略是不同的,以 macOS 为例, 最新的 HFS+APFS 默认大小写不敏感:

APFS accepts only valid UTF-8 encoded filenames for creation, and preserves both case and normalization of the filename on disk in all variants. APFS, like HFS+, is case-sensitive on iOS and is available in case-sensitive and case-insensitive variants on macOS, with case-insensitive being the default.

In macOS High Sierra, APFS is normalization-insensitive in both the case-insensitive and case-sensitive variants, using a hash-based native normalization scheme. In iOS 11, APFS is normalization-insensitive as well, using either a native normalization scheme (erase restores only) or runtime normalization scheme (upgrades from previous versions). Runtime normalization will also be available in iOS 10.3.3 and macOS Sierra 10.12.6. Being normalization-insensitive ensures that normalization variants of a filename cannot be created in the same directory, and that a filename can be found with any of its normalization variants. This means that developers don’t need to do any additional work to ensure correct normalization behavior in these versions of macOS and iOS.
How does Apple File System handle filenames?

默认情况下,windowsmac 的文件系统都是大小写不敏感的。需要说明的是,我们的大小写敏感实际关系到的是所使用的 文件系统

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. git config documentation