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 警告是正常的跨系统换行符兼容提示,无需额外处理。

相关推荐
weixin_156241575769 小时前
基于YOLOv8深度学习花卉识别系统摄像头实时图片文件夹多图片等另有其他的识别系统可二开
大数据·人工智能·python·深度学习·yolo
AI_Claude_code9 小时前
ZLibrary访问困境方案三:Web代理与轻量级转发服务的搭建与优化
爬虫·python·web安全·搜索引擎·网络安全·web3·httpx
小陈工9 小时前
2026年4月7日技术资讯洞察:下一代数据库融合、AI基础设施竞赛与异步编程实战
开发语言·前端·数据库·人工智能·python
时空无限9 小时前
ansible 由于不同主机 python 版本不同执行报错
python·ansible
ZhengEnCi9 小时前
P2E-Python字典操作完全指南-从增删改查到遍历嵌套的Python编程利器
python
alanesnape9 小时前
使用AVL平衡树和列表实现 map容器 -- 附加测试/python代码
python·map·avl 平衡树·bst树·二叉树旋转
爱学英语的程序员9 小时前
Git 提交 LF will be replaced by CRLF the next time Git touches it 报错
git
卤炖阑尾炎10 小时前
Python 网络编程实战:从 TCP/UDP 基础到高并发服务器开发
网络·python·tcp/ip
qq_3391911410 小时前
服务器git pull每次都要输入密码,linux 设置git登录,linux设置git只输入一次账户密码
git
weixin_5134499610 小时前
walk_these_ways项目学习记录第八篇(通过行为多样性 (MoB) 实现地形泛化)--策略网络
开发语言·人工智能·python·学习