Filename too long in git for windows

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

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.

Surely I'm doing something wrong: I did git config core.longpaths true and git add . then git commit. Everything went well. But when I now do a git status, I get a list of files with Filename too long, e.g.

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 app with the angular-generator ("yo angular") and remove node_modules from the .gitignore file. Then repeating the aforementioned git commands.

What am I missing here?

回答1:

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.

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

You can circumvent this by using another git-client on windows or set core.longpaths to true as explained in other answers below.



回答2:

You should be able to run the command

git config --system core.longpaths true 

or add it to one of your git config files manually to turn this functionality on, once you are on a supported version of git. It looks like maybe 1.9.0 and after.



回答3:

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. This command only solves the problem by being specific to the current project.



回答4:

create .gitconfig and add

[core] longpaths = true 

You can create file in project location(not sure) and also in global location in my case location is c:Users{name}\



回答5:

The better solution is enable the longpath parameter from git.

git config --system core.longpaths true 

But a work arround that works is remove node_modules folter from git.

$ git rm -r --cached node_modules $ vi .gitignore 

Add node_modules in new row inside .gitignore file. After do this, push your modifications.

$ git add .gitignore $ git commit -m "node_modules removed" $ git push 


回答6:

To be entirely sure that it takes effect immediately after the repository is initialized, but before the remote history is fetched or any files checked out, it is safer to use it this way:

git clone -c core.longpaths=true 

-c key=value

Set a configuration variable in the newly-created repository; this takes effect immediately after the repository is initialized, but before the remote history is fetched or any files checked out. The key is in the same format as expected by git-config1 (e.g., core.eol=true). If multiple values are given for the same key, each value will be written to the config file. This makes it safe, for example, to add additional fetch refspecs to the origin remote.

More info



回答7:

I had this error too but in my case the cause was using an outdated version of npm, v1.4.28.

Updating to npm v3 followed by

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).



回答8:

Move repo to root of your drive (Temporary fix)

You can try to temporarily move the local repo (the entire folder) to the root of your drive or as close to the root as possible.

Since the path is smaller at the root of the drive, it sometimes fixes the issues.

On windows, I'd move this to C:\ or another drive's root



回答9:

Steps:

  1. Start Git Bash as Administrator
  2. Run command git config --system core.longpaths true


回答10:

if you are working with your encrypted partition, consider moving the folder to an unencrypted partition, for example a /tmp, running git pull, and then moving back.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!