开启git对文件名的大小写敏感

git默认是不不开始文件名的大小写敏感的, 当你在上传文件时, 如果你修改了文件名的大小写, git会认为你并没有进行修改

我是在做github pages时修改文件名大小写,发现url无法定位到文件导致404时发现git的这个默认设置的

解决方法如下

打开你的git bash, cd到目标git仓库后, 键入以下指令来开启git对该仓库下文件名的大小写敏感

1
$ git config core.ignorecase false

或者在任意目录修改全局设置

1
$ git config --global core.ignorecase false

这样你所有的仓库都会开启大小写敏感了, 一劳永逸


当然还有一种方法, 先删除文件, push, 再添加文件, push 这种方法太暴力不做推荐


最后提一下, git之所以默认不开启文件名的大小写敏感, 可能是在跟随文件系统。因为我使用的windows系统是文件名大小写不敏感的, 如果git允许A.txta.txt同时存在, windows的文件系统却认为他们是一个文件,不允许他们共存, 便产生了冲突。相比之下, linux的文件系统的大小写是敏感的, 便又是另一幅光景了。

以下内容截取自git官方文档

core.ignoreCase

Internal variable which enables various workarounds to enable Git to work better on filesystems that are not case sensitive, like APFS, HFS+, FAT, NTFS, etc. 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.

Git relies on the proper configuration of this variable for your operating and file system. Modifying this value may result in unexpected behavior.

reference

https://git-scm.com/docs/git-config

开启git对文件名的大小写敏感

https://matrix4f.com/Git/git-ignorecase/

Author

oxine

Posted on

2020-02-28

Updated on

2020-03-04

Licensed under

Comments

昵称处填入QQ号,自动同步QQ头像与ID