git add . 添加超长文件名报错了怎么办?

报错信息如下:

txt 复制代码
aced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/JSON.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/api/AccountApi.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/api/DerivativesTradingPortfolioMarginProRestApi.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/api/MarketDataApi.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/BnbTransferRequest.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/BnbTransferResponse.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/ChangeAutoRepayFuturesStatusRequest.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/ChangeAutoRepayFuturesStatusResponse.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/FundAutoCollectionRequest.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/FundAutoCollectionResponse.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/FundCollectionByAssetRequest.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/FundCollectionByAssetResponse.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/GetAutoRepayFuturesStatusResponse.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/GetPortfolioMarginAssetLeverageResponse.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/GetPortfolioMarginAssetLeverageResponseInner.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/GetPortfolioMarginProAccountBalanceResponse.java', LF will be replaced by CRLF the next time Git touches it
error: open("binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/GetPortfolioMarginProAccountBalanceResponseInner.java"): Filename too long
error: unable to index file 'binance-connector-java-master/clients/derivatives-trading-portfolio-margin-pro/src/main/java/com/binance/connector/client/derivatives_trading_portfolio_margin_pro/rest/model/GetPortfolioMarginProAccountBalanceResponseInner.java'
fatal: adding files failed

解决办法:

你现在执行 git add . 时,除了之前的 LF/CRLF 换行符警告,还遇到了 "Filename too long"(文件名太长) 的致命错误,导致 Git 无法索引这个 Java 文件,最终添加文件失败,你想解决这个问题。

错误原因分析

LF/CRLF 警告:和之前一样,只是 Windows 下 Git 自动转换换行符的兼容提示,非致命错误,无需处理;

Filename too long 致命错误:Windows 系统默认限制文件路径长度(传统上限是 260 个字符),而这个 Java 文件的完整路径(从 K:/study/... 到文件本身)超过了这个限制,Git 无法处理这种超长路径的文件,因此报出 "无法索引文件" 的错误,直接导致 git add 失败。

解决方案(优先推荐方案 1,最简单)

方案 1:修改 Git 配置(最简便,仅针对 Git 生效,无需管理员权限)

这个方案只调整 Git 的设置,让它支持超长路径,是新手最易操作的方式:

bash 复制代码
# 1. 全局开启 Git 对长路径的支持(--global 表示所有仓库都生效)
git config --global core.longpaths true

# 2. (可选)清理之前失败的暂存记录(避免残留问题)
git rm --cached -r .

# 3. 重新执行 git add .
git add .

方案 2:修改 Windows 系统设置(彻底解决系统级限制,需管理员权限)

如果方案 1 执行后仍报错,可通过修改系统策略彻底解除路径长度限制(注意:部分 Windows 家庭版没有 gpedit.msc,优先用方案 1 即可):

按下 Win+R 组合键,输入 gpedit.msc,按回车打开「本地组策略编辑器」;

依次展开左侧菜单:计算机配置 → 管理模板 → 系统 → 文件系统 → NTFS文件系统;

找到右侧的「启用 NTFS 长路径」,双击打开设置窗口;

选择「已启用」,点击「确定」保存;

关闭并重新打开 Git Bash(MINGW64)窗口,再次执行 git add .。

总结

核心错误是 Windows 默认的文件路径长度限制,导致 Git 无法索引超长路径的 Java 文件;

优先执行 git config --global core.longpaths true 开启 Git 长路径支持,这是最简单、无权限要求的解决方法;

LF/CRLF 警告是正常的跨系统换行符兼容提示,无需额外处理。

相关推荐
Lucas_coding6 小时前
【Claude Code Router】 Claude Code 兼容 OpenAI 格式 API, Claude code 接入本地部署模型
人工智能·python
测试员周周6 小时前
【AI测试系统】第5篇:从 Archon 看 AI 工程化落地:为什么"确定性编排+AI 弹性智能"是终局?
人工智能·python·测试
大飞记Python6 小时前
【2026更新】Python基础学习指南(AI版)——04数据类型
开发语言·人工智能·python
Elastic 中国社区官方博客7 小时前
Elastic 和 Cursor 合作 加速 上下文工程 与 coding agents
大数据·人工智能·elasticsearch·搜索引擎·全文检索
Hello eveybody8 小时前
介绍一下背包DP(Python)
开发语言·python·动态规划·dp·背包dp
2301_795099748 小时前
让 CSS Grid 自适应容器尺寸的动态布局方案
jvm·数据库·python
呆萌的代Ma8 小时前
python读取并加载.env的配置文件
python
Muyuan19988 小时前
27.RAG 系统中的上下文充分性判断:从 Chunk 数量、FAISS 距离到 LLM Relevance Gate
python·django·pdf·fastapi·faiss
U盘失踪了9 小时前
python curl转python脚本
开发语言·chrome·python
FQNmxDG4S9 小时前
Java泛型编程:类型擦除与泛型方法的应用场景
java·开发语言·python