如何在Git提交大小写敏感的文件
背景
下午在搞代码部署的时候, 遇到一个文件大小写的问题, 问题比较简单, 但是也简单整理下, 分享给大家。
正文
下午在搞代码部署的时候, 线上编译失败了, 看了下错误日志:
#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'文件没找到, 可是我看了看代码, 这不是好好地在这吗?
到线上仓库看了一下, 文件名是小写的 userModal。
怪不得文件找不到。
知道错误原因就很好办了。
直接把git的忽略大小写关了:
git config core.ignorecase false然后重新提交, 就OK了。
除去这个做法, 你也可以这样:
git mv File file.tmp
git mv file.tmp file然后重新提交, 问题解决, 顺利部署。
ignorecase
下面我们就看看这个ignorecase:
在git官方文档中, 相关描述如下:
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-clone或git-init。
用这两个命令创建repository的时候,core.ignoreCase会被设置成true.
这下就明白了。
原文:https://segmentfault.com/a/1190000021847996
本文内容仅供个人学习、研究或参考使用,不构成任何形式的决策建议、专业指导或法律依据。未经授权,禁止任何单位或个人以商业售卖、虚假宣传、侵权传播等非学习研究目的使用本文内容。如需分享或转载,请保留原文来源信息,不得篡改、删减内容或侵犯相关权益。感谢您的理解与支持!