最近想学习 DDD 架构,顺便克隆了一个有名的 DDD 框架开源项目 刚果商城(CongoMall) ,结果 git clone
时遇到了如下错误:

bash
unable to create file
congomall-test-all/congomall-flow-monitor-agent-test/congomall-flow-monitor-message-provider-test/src/main/java/org/opengoofy/congomall/test/flowmonitor/agent/message/provide/rocketmq/FlowMonitorSpringCloudStreamRocketMQTest.java:
Filename too long
unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status' and retry with 'git restore --source=HEAD :/'
大概意思是:Windows 文件路径过长 (默认 MAX_PATH = 260
),导致 Git 无法创建对应文件。
我网上查了下解决办法,主要有几种,我用的是 方法 C(因为最简单,哈哈😁)。
解决方案
1. 启用 Windows 的长路径支持
Windows 10/11 可以通过组策略或注册表开启长路径。
方法 A:组策略
Win + R
输入gpedit.msc
打开组策略编辑器。- 路径:
计算机配置 -> 管理模板 -> 系统 -> 文件系统 -> 启用 Win32 长路径
。 - 将其设置为 启用。
- 重启电脑。
方法 B:注册表
如果你的 Windows 没有组策略(家庭版常见),可以用注册表:
powershell
reg add HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f
然后重启电脑即可。
方法 C:Git 长路径支持(推荐)
直接让 Git 支持长路径:
bash
git config --system core.longpaths true
2. 克隆到短路径目录
避免路径过长,比如:
bash
cd C:\
git clone https://github.com/xxx/xxx.git c:\repo
3. 使用浅克隆(--depth 1
)
如果只想快速测试代码,不需要完整历史:
bash
git clone --depth 1 https://github.com/xxx/xxx.git
4. Sparse Checkout(只下载指定目录)
只需要某些模块时可以这样:
bash
git clone --no-checkout https://github.com/xxx/xxx.git
cd xxx
git sparse-checkout init --cone
git sparse-checkout set some/sub/path
git checkout
5. 如果仓库已部分克隆
可以重新签出:
bash
git config core.longpaths true
git restore --source=HEAD :/
总结
最推荐的方式是直接执行:
bash
git config --system core.longpaths true
或者把项目克隆到 路径较短 的目录(如 C:\repo
)。