惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

PCI Perspectives
PCI Perspectives
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
T
The Blog of Author Tim Ferriss
罗磊的独立博客
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
Recorded Future
Recorded Future
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
Recent Announcements
Recent Announcements
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
T
Threatpost
The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
Scott Helme
Scott Helme
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
V
Visual Studio Blog
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
AI
AI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Security Affairs
S
SegmentFault 最新的问题
C
Cisco Blogs
博客园 - 聂微东
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
量子位
T
The Exploit Database - CXSecurity.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Security Latest
Security Latest
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
The Last Watchdog
The Last Watchdog

阿尔的代码屋 | 全栈技术笔记

在 Android Termux 环境下安装 Hermes Agent 的踩坑与完美解决实践 开发日志| 阿尔的代码屋 VS Code 连接 WSL 精确每 10 分钟掉线 排坑笔记 | 阿尔的代码屋 Android 模拟器代理联网与 No Internet WiFi 锁死排坑笔记 | 阿尔的代码屋 [object Object] typing_extensions 有用(四):使用 TypeIs 替代危险的 cast,做最严谨的类型收窄 | 阿尔的代码屋 GoRouter 结合 Isar 运行 Widget 测试并发/粘性线程死锁卡死排坑笔记 | 阿尔的代码屋 typing_extensions 有用(三):使用 Unpack 结合 TypedDict 给 **kwargs 装上透视眼 | 阿尔的代码屋 typing_extensions 有用(二):使用 @override 打造重构代码时的“防呆神器” | 阿尔的代码屋 Flutter 并发测试踩坑实录 - IsarCore 动态库下载冲突与 Widget 测试 HTTP 拦截全链路解决 | 阿尔的代码屋 typing_extensions 有用(一):使用 Self 终结继承时的类型推断灾难 | 阿尔的代码屋 基于 Cloudflare Pages 的纯前端 WebAssembly 应用自动化部署实践 | 开发日志 | 阿尔的代码屋 基于 VS Code 远程开发的 GPU Docker 容器自动清理方案实践 开发日志| 阿尔的代码屋 Patrol iOS 集成测试排坑实录 - xcodebuild exit code 70 全链路解决 | 阿尔的代码屋 Flutter E2E 测试从 integration_test 迁移到 Patrol - 实践笔记 | 阿尔的代码屋 Linux/macOS 下 micromamba 报错 Shard Index not available 与极度卡顿 排坑笔记 | 阿尔的代码屋 critical libmamba Shell not initialized micromamba报错 subprocess 无法修改父 Shell - 排坑笔记 | 阿尔的代码屋 VS Code Remote-SSH: 彻底告别重复输入密码 - 排坑笔记 | 阿尔的代码屋 Git 报警: inexact rename detection was skipped - 排坑笔记 | 阿尔的代码屋 解决群晖 NAS SSL 证书自动部署难题 | 阿尔的代码屋 Windows 下 Git error: fatal: refusing to work with credential missing host field - 排坑笔记 | 阿尔的代码屋 VS Code 调试 Python 第三方库源码的配置 - 开发技巧| 阿尔的代码屋 VS Code Remote Tunnels本地连接调试Kaggle GPU - 开发技巧| 阿尔的代码屋 记录2026年零预约港卡开户实录避坑 告别孤岛:拥抱 MCP 协议,为大模型打造标准“USB 接口” - 大模型实战 08 完结篇 | 阿尔的代码屋 从 ReAct 到 Workflow:基于云端 API 构建事件驱动的智能体 - 大模型实战 07 额外篇 | 阿尔的代码屋 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent - 大模型实战 07 | 阿尔的代码屋 在 Kaggle 上用 Unsloth 极速微调 Qwen3 - 大模型实战 06 | 阿尔的代码屋 大模型微调实战详解 - 大模型实战 05 | 阿尔的代码屋 基于 ChromaDB 打造工程级 RAG 系统 - 大模型实战 04 | 阿尔的代码屋 拆解 Transformers 原理与图解 - 大模型实战 03 | 阿尔的代码屋 云端炼丹房 2:Kaggle 上手指南 - 大模型实战 03预备 | 阿尔的代码屋 云端炼丹房:Google Colab 免费 GPU 上手指南 - 大模型实战 03预备 | 阿尔的代码屋 Open WebUI 部署与 RAG 实战 - 大模型实战 02 | 阿尔的代码屋
Windows下Git error: open(xxxx) Filename too long - 排坑笔记 | 阿尔的代码屋
Algieba · 2026-03-24 · via 阿尔的代码屋 | 全栈技术笔记

核心摘要 (TL;DR)

  • 问题现象:在 Windows 环境下执行 git add 等操作时,由于项目目录嵌套过深或文件绝对路径过长(通常超过260个字符),导致 Git 抛出 Filename too long 错误,无法将文件纳入版本控制。
  • 根本原因:受限于 Windows 传统的 MAX_PATH 长度限制,且 Git for Windows 出于对旧版系统的兼容性考虑,默认关闭了长路径支持。
  • 极速解法:直接在终端执行 git config --global core.longpaths true 开启 Git 全局长路径支持即可完美解决。

问题概览卡片

基本信息

  • 问题分类:Git 核心配置 / Windows 文件系统兼容性
  • 异常摘要Filename too long 导致无法执行 git add
  • 环境说明
    • 操作系统:Windows 11 专业版 (Version 23H2)
    • 工具版本:Git for Windows 2.x.x
  • 触发条件:在深层嵌套的目录结构中创建了具有描述性长文件名的文件。
  • 报错摘要error: unable to index file ... fatal: adding files failed

错误日志复现

1
2
3
error: open("<Root>/<Deep_Hierarchy>/<Long_Sub_Path>/<Desensitized_Filename>.md"): Filename too long
error: unable to index file '<Root>/<Deep_Hierarchy>/<Long_Sub_Path>/<Desensitized_Filename>.md'
fatal: adding files failed

1. 现象描述

在进行复杂的模块化开发或多代理架构设计时,目录深度往往会随着项目推进而增加。当某个文件的绝对路径长度(包含项目根目录路径)接近或超过 260 个字符时,Git 在执行索引(Indexing)操作时会因为触发操作系统的路径长度保护机制而报错。

即使在 Windows 资源管理器中能够正常查看或编辑该文件,Git 默认的兼容性设置也会阻止将其纳入版本控制。

2. 根本原因分析

  1. Windows 历史局限性:传统 Windows API 受到 MAX_PATH 限制,定义最大路径长度为 260 个字符。
  2. Git 默认行为:为了保持对旧版本 Windows 系统的兼容,Git for Windows 的 core.longpaths 参数在初始化时通常默认为 false
  3. 路径累加效应:路径长度 = 磁盘盘符路径 + 用户目录路径 + 项目根目录 + 文件夹嵌套层级 + 长文件名。在 Windows 环境下,由于用户目录路径通常较长,很容易在项目深度增加时触及上限。

3. 解决方案

方案一:修改 Git 全局配置(推荐)

这是最直接的解决方式,通过开启 Git 内部对长路径的支持,绕过 API 限制。

在终端执行:

1
git config --global core.longpaths true

配置验证:

1
git config --get core.longpaths

方案二:修改系统注册表(系统级支持)

如果其他开发工具(如 IDE 内置的 Git 插件)依然报错,可以开启系统级的长路径支持:

  1. 快捷键 Win + R 输入 regedit
  2. 定位至:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
  3. 找到 LongPathsEnabled,将其值由 0 改为 1

4. 预防与改进建议

  • 缩减路径冗余:将项目存放于较浅的盘符目录下(例如 D:/dev/ 而非 C:/Users/Admin/Documents/Work/Projects/...)。
  • 语义化缩写:在目录命名中使用标准缩写(如 Architecture 缩写为 arch),减少字符占用。
  • 自动化环境检查:在团队协作的 README.md 中注明此配置项,或在项目初始化脚本中自动执行该配置。

5. 总结

通过开启 core.longpaths 配置,可以有效解决 Windows 平台下因文件路径过深导致的 Git 索引失败问题。这种规范化的卡片记录方式,旨在为复杂项目的环境搭建提供快速参考。