Windows 10 文件名大小写敏感设置

Linux 天然支持文件名大小写区分,同一目录下 abcABC 是两个独立的文件。Mac OS 也可以通过格式化时选择区分大小写的文件系统来实现。Windows 默认不支持,NTFS 虽然存储时保留大小写,但查找时始终不区分。

问题来源

在 Windows 上执行 git clone 克隆某个 Linux 内核相关仓库时,出现了下面的警告:

复制代码
warning: the following paths have collided (e.g. case-sensitive paths
on a case-insensitive filesystem) and only one from the same
colliding group is in the working tree:
  'include/uapi/linux/netfilter/xt_CONNMARK.h'
  'include/uapi/linux/netfilter/xt_connmark.h'
  'include/uapi/linux/netfilter/xt_DSCP.h'

原因很直接:仓库里同时存在大写和小写的同名文件,在"不区分大小写"的 Windows 文件系统上,后克隆的文件把先克隆的直接覆盖了,Git 检测到冲突就报了这个 warning。

解决方法

有两种方式可以解决:在 WSL2 终端里操作,或者用 fsutil.exe 给指定目录开启大小写敏感。

用管理员身份打开 cmd 或 PowerShell,切到 C:\Windows\System32,执行:

复制代码
fsutil.exe file SetCaseSensitiveInfo E:\github_code enable

成功的话会看到:

复制代码
PS C:\Windows\System32> fsutil.exe file SetCaseSensitiveInfo E:\github_code enable
已启用目录 E:\github_code 的区分大小写属性。

这个设置只对指定目录生效,不影响系统其他地方。

前提条件

以下四点缺一不可,否则命令会失败或报错:

  1. Windows 10 需要 1803(2018 年 4 月更新)或更高版本
  2. 已安装 WSL(Windows Subsystem for Linux)
  3. 目标目录所在分区为 NTFS 格式
  4. 以管理员身份运行终端
相关推荐
Master_H_ice18 小时前
Claude Code安装试用记录(Windows)
windows·claude code
芳草萋萋鹦鹉洲哦21 小时前
【windows】nginx如何注册为开机自启的服务(WinSW实现)
运维·windows·nginx
好名字更能让你们记住我21 小时前
vmware虚拟机安装Windows10镜像【超详细图文版】!!!
windows·系统安装·vmware·虚拟机·图文教程
副露のmagic1 天前
字符串章节 leetcode 思路&实现
windows·python·leetcode
Java 码农1 天前
Windows 系统安装 Claude Code 完整教程
windows
无籽西瓜a1 天前
详解bat脚本:语法、常见用法、注意事项、示例
windows·batch·cmd·自动化工具
无极低码1 天前
windows 程连接 Oracle 报 ORA-12541
数据库·windows·oracle
God__is__a__girl1 天前
Docker Desktop 在 Windows 上启动失败:500 Internal Server Error 完整排查与修复指南
windows·docker·容器
桌面运维家1 天前
Windows 10音频故障排除:驱动、设备、DirectX修复指南
windows·音视频
盘古工具1 天前
解锁你的文档:如何安全移除Word打开密码
windows·安全