Git截断长路径致stat失败问题求助
Git路径在128字符处截断导致Composer Install失败(Linux环境)
问题描述
执行composer install时触发Git错误,路径被在128字符位置截断,报错如下:
fatal: failed to stat '/home/my/128/chars/long/path/vendor/oxid-esales/oxideshop-unified-namespace-generato': No such file or directory
可见路径末尾的generator被截断,完整路径应为oxideshop-unified-namespace-generator,恰好触发128字符的截断阈值。
Composer自动执行的Git命令如下:
git clone --no-checkout '/home/user/.cache/composer/vcs/https---github.com-oxid-eshop-gpl-oxideshop-unified-namespace-generator.git/' '/home/my/128/chars/long/path/vendor/oxid-esales/oxideshop-unified-namespace-generator' --dissociate --reference '/home/user/.cache/composer/vcs/https---github.com-oxid-eshop-gpl-oxideshop-unified-namespace-generator.git/' && cd '/home/my/128/chars/long/path/vendor/oxid-esales/oxideshop-unified-namespace-generator' && git remote set-url origin -- 'git@github.com:oxid-eshop-gpl-oxideshop-unified-namespace-generator.git'
错误发生在执行git remote set-url步骤,已尝试git config --global core.longpaths true但问题依旧,环境为Linux服务器。
原因分析
- Git内部静态缓冲区限制:早期Git的部分内部函数使用了128字符的静态缓冲区处理路径,这个限制源于旧POSIX规范对PATH_MAX的保守定义。即便现代Linux系统本身支持更长路径,若Git版本较旧或编译时未适配,就会触发截断问题。
- core.longpaths不适用Linux:
core.longpaths配置是专门为Windows设计的,用来绕过Windows默认的260字符路径限制,在Linux环境下该配置完全不起作用——Linux没有全局PATH_MAX限制,仅受文件系统和进程局部配置影响,通常远大于128。
解决方法
- 升级Git到最新稳定版:新版Git已修复这类静态缓冲区限制问题,通过系统包管理器升级即可:
若为源码编译的Git,确保使用最新源码与现代编译选项,不要启用# Debian/Ubuntu 系 sudo apt update && sudo apt upgrade git # RHEL/CentOS 系 sudo yum update gitNO_LONG_PATHS这类限制参数。 - 缩短项目根路径:临时规避方案是将项目所在的长路径改短,比如把
/home/my/128/chars/long/path/改为/home/my/short-proj/,让vendor下的包路径长度不触发128字符阈值。
内容的提问来源于stack exchange,提问作者ivoba
相关产品推荐
相关产品推荐

