我使用Git-1.9.0-preview20140217 for Windows。据我所知,这个版本应该解决文件名过长的问题。但对我来说不是。

当然我做错了什么:我做了git配置核心。Longpaths true和git add。然后git提交。一切都很顺利。但是当我现在做一个git状态时,我得到了一个文件名太长的文件列表,例如:

node_modules/grunt-contrib-imagemin/node_modules/ pngquent -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命令。

我错过了什么?


当前回答

您还可以尝试启用长文件路径。

如果你运行Windows 10家庭版,你可以更改注册表以启用长路径。

进入regedit中的HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem,然后将LongPathsEnabled设置为1。

如果你有Windows 10 Pro或Enterprise,你也可以使用本地组策略。

在gpedit中进入“计算机配置→管理模板→系统→文件系统”。打开“Enable Win32长路径”,设置为“Enabled”。

其他回答

您应该能够运行该命令

git config --system core.longpaths true

或者手动将其添加到您的Git配置文件中以开启此功能,一旦您使用了受支持的Git版本。它看起来可能是1.9.0或之后的版本。

TortoiseGit (Windows)

对于使用TortoiseGit For Windows的人,我这样做:

(1)右键单击包含项目的文件夹。选择“TortoiseGit -> Settings”。

(2)在“Git”页签,点击“Edit local . Git /config”按钮。

(3)在弹出的文本文件中,在[core]部分下添加: Longpaths = true

保存并关闭所有内容,然后重新尝试提交。对我来说,这很有效。

我希望这能最大限度地减少任何可能的系统范围问题,因为我们不是编辑全局的.gitconfig文件,而是只编辑这个特定存储库的文件。

更好的解决方案是从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

如果您正在使用加密分区,请考虑将文件夹移动到未加密分区(例如/tmp),运行git pull,然后移动回来。

在Windows中,你可以遵循这些对我很有用的步骤。

以管理员身份打开cmd或git bash

以管理员身份从cmd或git bash中输入以下命令

git config --system core.longpaths true

这将允许全局访问长路径 现在您可以克隆存储库,而不存在长路径的问题