如何在Git提交大小写敏感的文件

Image result for git

背景

下午在搞代码部署的时候, 遇到一个文件大小写的问题, 问题比较简单, 可是也简单整理下, 分享给你们。html

正文

下午在搞代码部署的时候, 线上编译失败了, 看了下错误日志:webpack

#7 0.984 $ BABEL\_ENV=production webpack --config webpack/webpack.config.prod.js --colors
#7 19.58 ModuleNotFoundError: Module not found: Error: Can't resolve './UserModal' in '/workspace/src/pages/User/UserList'

文件没找到, 但是我看了看代码, 这不是好好地在这吗?git

到线上仓库看了一下, 文件名是小写的 userModalweb

怪不得文件找不到。app

知道错误缘由就很好办了。this

直接把git的忽略大小写关了:spa

git config core.ignorecase false

而后从新提交, 就OK了。3d

除去这个作法, 你也能够这样:日志

git mv File file.tmp
git mv file.tmp file

而后从新提交, 问题解决, 顺利部署。code

ignorecase

下面咱们就看看这个ignorecase

git官方文档中, 相关描述以下:

image.png

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, exceptgit-clone(1)orgit-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.

大意是说, 忽略大小写敏感是为了在不一样的文件系统上更好的工做。

好比APFS,HFS +,FAT,NTFS等。

例如,若是在目录列表里, Git指望找到一个文件叫Makefile,却找到了makefile,这时候,Git就假定它是同一文件,并继续将其记住为Makefile

这个值默认是false, 除了git-clonegit-init

用这两个命令建立repository的时候,core.ignoreCase会被设置成true.

这下就明白了。

结尾

平时不遇到实际的状况, 不太容易能注意到这点。

在这里总结下, 但愿看到的盆友能有个印象。

谢谢你们。

相关文章
相关标签/搜索