Windows版Git中的文件名太长

本文翻译自:Filename too long in Git for Windows

I'm using Git-1.9.0-preview20140217 for Windows. 我正在Windows上使用Git-1.9.0-preview20140217 As I know, this release should fix the issue with too long filenames. 据我所知,此版本应解决文件名过长的问题。 But not for me. 但是不适合我。

Surely I'm doing something wrong: I did git config core.longpaths true and git add . 当然,我做错了:我做了git config core.longpaths truegit add . and then git commit . 然后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: 但是,当我现在执行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

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. 对我来说,复制非常简单:只需使用Angular生成器(“ yo angular”)创建Yeoman Web应用程序, node_modules.gitignore文件中删除node_modules Then repeat the aforementioned Git commands. 然后重复上述Git命令。

What am I missing here? 我在这里想念什么?


#1楼

参考:https://stackoom.com/question/1Wixa/Windows版Git中的文件名太长


#2楼

Git has a limit of 4096 characters for a filename, except on Windows when Git is compiled with msys. Git的文件名限制为4096个字符,但在Windows上使用msys编译Git时除外。 It uses an older version of the Windows API and there's a limit of 260 characters for a filename. 它使用Windows API的较早版本,文件名限制为260个字符。

So as far as I understand this, it's a limitation of msys and not of Git. 据我了解,这是msys的限制,而不是Git的限制。 You can read the details here: https://github.com/msysgit/git/pull/110 您可以在此处阅读详细信息: https : //github.com/msysgit/git/pull/110

You can circumvent this by using another Git client on Windows or set core.longpaths to true as explained in other answers. 您可以通过在Windows上使用其他Git客户端来规避此问题,或将core.longpaths设置为true如其他答案所述。

git config --system core.longpaths true

Git is build as a combination of scripts and compiled code. Git是脚本和编译后代码的组合。 With the above change some of the scripts might fail. 通过上述更改,某些脚本可能会失败。 That's the reason for core.longpaths not to be enabled by default. 这就是默认情况下不启用core.longpaths的原因。

The windows documentation at https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file has some more information: https://docs.microsoft.com/zh-cn/windows/desktop/fileio/naming-a-file上的Windows文档提供了更多信息:

Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. 从Windows 10版本1607开始,MAX_PATH限制已从常见的Win32文件和目录功能中删除。 However, you must opt-in to the new behavior. 但是,您必须选择加入新行为。

A registry key allows you to enable or disable the new long path behavior. 注册表项允许您启用或禁用新的长路径行为。 To enable long path behavior set the registry key at HKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem LongPathsEnabled (Type: REG_DWORD) 若要启用长路径行为,请将注册表项设置为HKLM \\ SYSTEM \\ CurrentControlSet \\ Control \\ FileSystem LongPathsEnabled(类型:REG_DWORD)


#3楼

You should be able to run the command 您应该能够运行命令

git config --system core.longpaths true

or add it to one of your Git configuration files manually to turn this functionality on, once you are on a supported version of Git. 或在受支持的Git版本上手动将其添加到您的Git配置文件之一以启用此功能。 It looks like maybe 1.9.0 and after. 看起来可能是1.9.0及更高版本。


#4楼

I had this error too, but in my case the cause was using an outdated version of npm, v1.4.28. 我也有此错误,但就我而言,原因是使用了过时的npm v1.4.28版本。

Updating to npm v3 followed by 更新到npm v3,然后更新

rm -rf node_modules
npm -i

worked for me. 为我工作。 npm issue 2697 has details of the "maximally flat" folder structure included in npm v3 (released 2015-06-25). npm问题2697包含了npm v3(2015-06-25发布)中包含的“最大平坦”文件夹结构的详细信息。


#5楼

This might help: 这可能会有所帮助:

git config core.longpaths true

Basic explanation: This answer suggests not to have such setting applied to the global system (to all projects so avoiding --system or --global tag) configurations. 基本说明:此答案建议不要将此设置应用于全局系统(对所有项目--global避免使用--system--global标记)配置。 This command only solves the problem by being specific to the current project. 此命令仅通过特定于当前项目来解决问题。


#6楼

Create .gitconfig and add 创建.gitconfig并添加

[core]
longpaths = true

You can create the file in a project location (not sure) and also in the global location. 您可以在项目位置(不确定)和全局位置中创建文件。 In my case the location is C:\\Users\\{name}\\ . 在我的情况下,位置为C:\\Users\\{name}\\

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值