all

Windows 版 Git 中的文件名太长

发布于 2022-03-22 23:23:30

我正在使用Git-1.9.0-preview20140217Windows。据我所知,此版本应该解决文件名过长的问题。但不适合我。

我肯定做错了什么:我做了git config core.longpaths trueand git add .then git commit。一切顺利。但是当我现在做 a 时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”)创建一个Yeomannode_modules
Web 应用程序并从.gitignore文件中删除。然后重复上述 Git 命令。

我在这里想念什么?

关注者
0
被浏览
12
1 个回答
  • 面试哥
    面试哥 2022-03-22
    为面试而生,有面试问题,就找面试哥。

    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)



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看