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

相关推荐
BK贝壳4 小时前
亿级用户签到位图选型复盘:用 bool-hybrid-array 扛冷启动打卡,也把它和 Roaring/Redis 的边界测清楚了
数据结构·python·性能优化·numpy
2601_966949656 小时前
如何根据研究的起止时间截取分钟级行情?Python 实战与 QuantDash 数据处理指南
开发语言·python·pandas·量化交易·1024程序员节·股票数据·quantdash
在世修行10 小时前
智学文枢:页面切换与跨页数据预填
python·桌面应用·signal·1024程序员节·pyside·跨页跳转·状态预填
2601_9628857210 小时前
如何用 Python 把 K 线重采样成任意周期?
开发语言·python
打工仔折腾 AI10 小时前
在 Ubuntu ARM64 部署 Q1 V3.0 MuJoCo 模型:加载、单步推理与执行器响应解析
linux·运维·人工智能·python·深度学习·ubuntu·性能优化
信誓旦旦的程序猿11 小时前
【Python量化实战宝典 #21】北向资金跟随手册:聪明钱择时信号(Python 可跑)
python·1024程序员节·股票数据api·股票数据api接口·股票api数据接口·股票量化数据api·股票量化数据接口
严谨的麻辣烫11 小时前
静态 ISP 代理请求超时怎么排查?Python 与 curl 实战
python·http·requests·1024程序员节·网络排障
橙露12 小时前
git简明教程以及资源分享
大数据·git
KeepRobots13 小时前
11-01 温哥华不回拨:用 60 行 Python 查你的工单系统会不会差一小时(KeepRobots 工程笔记)
python
xiao77mwq13 小时前
你以为 OCR 慢?实测 81.3 s 里全是故障代价:如何把「定格态」消掉,让耗时从 6.5 s 到 13 倍差距显出原形
python