Windows 版 Git 中的文件名太长 [英] Filename too long in Git for Windows
问题描述
我在 Windows 上使用 Git-1.9.0-preview20140217
.据我所知,此版本应该可以解决文件名过长的问题.但不适合我.
I'm using Git-1.9.0-preview20140217
for Windows. As I know, this release should fix the issue with too long filenames. But not for me.
我肯定做错了什么:我做了 git config core.longpaths true
和 git add .
然后是 git commit
.一切顺利.但是当我现在执行 git status
时,我得到一个 Filename too long
的文件列表,例如:
Surely I'm doing something wrong: I did git config core.longpaths true
and git add .
and then git commit
. Everything went well. But when I now do a git status
, I get a list of files with Filename too long
, for example:
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
对我来说,重现非常简单:只需创建一个 Yeoman 网络应用程序使用 Angular 生成器(yo angular")并从 .gitignore
文件中删除 node_modules
.然后重复前面提到的 Git 命令.
It is quite simple to reproduce for me: just create a Yeoman web application with the Angular generator ("yo angular") and remove node_modules
from the .gitignore
file. Then repeat the aforementioned Git commands.
我在这里遗漏了什么?
推荐答案
Git 的文件名限制为 4096 个字符,但在 Windows 上使用 msys 编译 Git 时除外.它使用旧版本的 Windows API,文件名限制为 260 个字符.
Git has a limit of 4096 characters for a filename, except on Windows when Git is compiled with msys. It uses an older version of the Windows API and there's a limit of 260 characters for a filename.
据我所知,这是 msys 而不是 Git 的限制.您可以在此处阅读详细信息:https://github.com/msysgit/git/pull/110
So as far as I understand this, it's a limitation of msys and not of Git. You can read the details here: https://github.com/msysgit/git/pull/110
您可以通过在 Windows 上使用另一个 Git 客户端或将 core.longpaths
设置为 true
来规避此问题,如其他答案所述.
You can circumvent this by using another Git client on Windows or set core.longpaths
to true
as explained in other answers.
git config --system core.longpaths true
Git 是作为脚本和编译代码的组合构建的.通过上述更改,某些脚本可能会失败.这就是默认情况下不启用 core.longpaths 的原因.
Git is build as a combination of scripts and compiled code. With the above change some of the scripts might fail. That's the reason for core.longpaths not to be enabled by default.
Windows 文档位于 https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later 有更多信息:
The windows documentation at https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later has some more information:
从 Windows 10 版本 1607 开始,MAX_PATH 限制已经从常见的 Win32 文件和目录功能中删除.然而,你必须选择接受新行为.
Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior.
注册表项允许您启用或禁用新的长路径行为.要启用长路径行为,请将注册表项设置为HKLMSYSTEMCurrentControlSetControlFileSystem LongPathsEnabled(类型:REG_DWORD)
A registry key allows you to enable or disable the new long path behavior. To enable long path behavior set the registry key at HKLMSYSTEMCurrentControlSetControlFileSystem LongPathsEnabled (Type: REG_DWORD)
这篇关于Windows 版 Git 中的文件名太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!