[英]Filename too long in Git for Windows
我将Git-1.9.0-preview20140217
用于 Windows。 据我所知,此版本应该解决文件名过长的问题。 但不适合我。
我肯定做错了什么:我做了git config core.longpaths true
和git add.
然后git commit
。 一切顺利。 但是当我现在执行git status
时,我会得到一个Filename too long
的文件列表,例如:
node_modules/grunt-contrib-imagemin/node_modules/pngquant-bin/node_modules/bin-wrapper/node_modules/download/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-handle-source-errors.js: Filename too long
对我来说重现非常简单:只需使用 Angular 生成器(“yo angular”)创建一个Yeoman web 应用程序,然后从.gitignore
文件中删除node_modules
。 然后重复前面提到的 Git 命令。
我在这里想念什么?
Git 的文件名限制为 4096 个字符,但在 Windows 上使用 msys 编译 Git 时除外。 它使用旧版本的 Windows API,文件名限制为 260 个字符。
所以据我所知,这是 msys 而不是 Git 的限制。 您可以在此处阅读详细信息: https : //github.com/msysgit/git/pull/110
您可以通过在 Windows 上使用另一个 Git 客户端或将core.longpaths
设置为true
来规避此问题,如其他答案中所述。
git config --system core.longpaths true
Git 是作为脚本和编译代码的组合构建的。 通过上述更改,某些脚本可能会失败。 这就是默认情况下不启用 core.longpaths 的原因。
https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-上的Windows文档1607 及更高版本有更多信息:
从 Windows 10 版本 1607 开始,MAX_PATH 限制已从常见的 Win32 文件和目录函数中删除。 但是,您必须选择加入新行为。
注册表项允许您启用或禁用新的长路径行为。 要启用长路径行为,请将注册表项设置为 HKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem LongPathsEnabled(类型:REG_DWORD)
您应该能够运行命令
git config --system core.longpaths true
或手动将其添加到您的 Git 配置文件之一以打开此功能,一旦您使用受支持的 Git 版本。 看起来可能是 1.9.0 及之后的版本。
这可能有帮助:
git config core.longpaths true
基本解释:此答案建议不要将此类设置应用于全局系统(应用于所有项目,因此避免--system
或--global
标记)配置。 此命令仅通过特定于当前项目来解决问题。
编辑:
对于那些没有被授予全局更改 git 设置的权限,这是与“权限被拒绝”问题相关的重要答案。
git config --system core.longpaths true
注意:如果第 2 步不起作用或出现任何错误,您也可以尝试运行以下命令:
git config --global core.longpaths true
在此处阅读有关git config
更多信息。
创建 .gitconfig 并添加
[core]
longpaths = true
您可以在项目位置(不确定)和全局位置创建文件。 在我的情况下,位置是C:\\Users\\{name}\\
。
更好的解决方案是从 Git 启用 longpath 参数。
git config --system core.longpaths true
但有效的解决方法是从 Git 中删除 node_modules 文件夹:
$ git rm -r --cached node_modules
$ vi .gitignore
在 .gitignore 文件中的新行中添加 node_modules。 执行此操作后,推送您的修改:
$ git add .gitignore
$ git commit -m "node_modules removed"
$ git push
执行git config --system core.longpaths true
向我抛出了一个错误:
“错误:无法锁定配置文件 C:\\Program Files (x86)\\Git\\mingw32/etc/gitconfig:权限被拒绝”
修复了在全局级别执行命令:
git config --global core.longpaths true
您也可以尝试启用长文件路径。
如果您运行 Windows 10 家庭版,则可以更改注册表以启用长路径。
转到regedit
HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem
,然后将LongPathsEnabled
设置为1
。
如果您有 Windows 10 专业版或企业版,您还可以使用本地组策略。
转到gpedit.msc
计算机配置→管理模板→系统→文件系统,打开Enable Win32 long paths并将其设置为Enabled 。
git config --global core.longpaths true
上面的命令对我有用。 使用“--system”给了我配置文件未锁定错误
git config --system core.longpaths true
git config --global core.longpaths true
在 Windows 中,您可以按照这些对我有用的步骤进行操作。
git config --system core.longpaths true
这将允许全局访问长路径
现在您可以克隆存储库而不会出现长路径问题
您可以尝试将本地存储库(整个文件夹)临时移动到驱动器的根目录或尽可能靠近根目录。
由于驱动器根部的路径较小,因此有时可以解决问题。
在 Windows 上,我会将其移至C:\\
或其他驱动器的根目录。
我也有这个错误,但就我而言,原因是使用了过时的 npm 版本 v1.4.28。
更新到 npm v3 然后
rm -rf node_modules
npm -i
为我工作。 npm 问题 2697 包含 npm v3(2015 年 6 月 25 日发布)中包含的“最大平面”文件夹结构的详细信息。
以管理员身份运行命令提示符,然后运行以下命令
git config --system core.longpaths 真
如果您正在使用加密分区,请考虑将文件夹移动到未加密分区,例如/tmp ,运行git pull
,然后移回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.