git pull 因错误文件名太长而中止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21123415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:35:11  来源:igfitidea点击:

git pull aborted with error filename too long

git

提问by Dave Martin

I'm using Windows as my OS, and working on a project with a friend who's using a Mac. He checked in code to our Github.

我使用 Windows 作为我的操作系统,并与一位使用 Mac 的朋友一起从事一个项目。他将代码签入了我们的 Github。

I was trying to git pull everything he did and it aborted with "filename too long" errors of 3rd party code.

我试图 git pull 他所做的一切,但它因 3rd 方代码的“文件名太长”错误而中止。

What can I do?

我能做什么?

回答by mloskot

The msysgit FAQ on Git cannot create a filedirectory with a long pathdoesn't seem up to date, as it still links to old msysgit ticket #110. However, according to later ticket #122the problem has been fixed in msysgit 1.9, thus:

Git上的 msysgit FAQ cannot create a filedirectory with a long path似乎不是最新的,因为它仍然链接到旧的 msysgit ticket #110。但是,根据后来的票 #122,该问题已在 msysgit 1.9 中得到解决,因此:

  1. Update to msysgit 1.9 (or later)
  2. Launch Git Bash
  3. Go to your Git repository which 'suffers' of long paths issue
  4. Enable long paths support with git config core.longpaths true
  1. 更新到 msysgit 1.9(或更高版本)
  2. 启动 Git Bash
  3. 转到“遭受”长路径问题的 Git 存储库
  4. 启用长路径支持 git config core.longpaths true

So far, it's worked for me very well.

到目前为止,它对我来说效果很好。

Be aware of important notice in comment on the ticket #122

请注意票据#122评论中的重要通知

don't come back here and complain that it breaks Windows Explorer, cmd.exe, bash or whatever tools you're using.

不要回到这里抱怨它破坏了 Windows 资源管理器、cmd.exe、bash 或您正在使用的任何工具。

回答by Daniel Hári

Solution1- set global config, by running this command:

解决方案 1- 通过运行以下命令设置全局配置:

git config --system core.longpaths true


Solution2- or you can edit directly your specific git config file like below:

解决方案 2- 或者您可以直接编辑您的特定 git 配置文件,如下所示:

YourRepoFolder -> .git -> config:

YourRepoFolder -> .git -> 配置:

[core]
    repositoryformatversion = 0
    filemode = false
    ...
    longpaths = true        <-- (add this line under core section)


Solution3- when cloning a new repository: here.

解决方案 3- 克隆新存储库时:此处

回答by xandermonkey

A few years late, but I'd like to add that if you need to do this in one fell swoop (like I did) you can set the config settings during the clone command. Try this:

晚了几年,但我想补充一点,如果您需要一举完成(就像我一样),您可以在克隆命令期间设置配置设置。尝试这个:

git clone -c core.longpaths=true <your.url.here>

回答by Pete

Open your.gitconfig file to add the longpaths property. So it will look like the following:

打开您的 .gitconfig 文件以添加 longpaths 属性。所以它看起来像下面这样:

[core]
symlinks = false
autocrlf = true
longpaths = true

回答by Tristan

As someone that has ran into this problem constantly with java repositories on Windows, the best solution is to install Cygwin (https://www.cygwin.com/) and use its git installation under all > devel > git.

作为在 Windows 上使用 java 存储库不断遇到此问题的人,最好的解决方案是安装 Cygwin ( https://www.cygwin.com/) 并在 all > devel > git 下使用其 git 安装。

The reason this is the best solution I have come across is since Cygwin manages the long path names so other provided commands benefit. Ex: find, cp and rm. Trust me, the real problem begins when you have to delete path names that are too long in Windows.

这是我遇到的最佳解决方案的原因是因为 Cygwin 管理长路径名称,因此其他提供的命令受益。例如:查找、cp 和 rm。相信我,当您必须删除 Windows 中太长的路径名时,真正的问题就开始了。

回答by Michael Ver

Try to keep your files closer to the file system root. More details : for technical reasons, Git for Windows cannot create files or directories when the absolute path is longer than 260 characters.

尽量让您的文件靠近文件系统根目录。更多细节:由于技术原因,当绝对路径超过 260 个字符时Git for Windows 无法创建文件或目录

回答by Kumar Abhishek

On windows run "cmd " as administrator and execute command.

在 Windows 上以管理员身份运行“cmd”并执行命令。

"C:\Program Files\Git\mingw64\etc>"
"git config --system core.longpaths true"

or you have to chmod for the folder whereever git is installed.

或者你必须为安装了 git 的文件夹 chmod 。

or manullay update your file manually by going to path "Git\mingw64\etc"

或 manullay 通过转到路径“Git\mingw64\etc”手动更新您的文件

[http]
    sslBackend = schannel
[diff "astextplain"]
    textconv = astextplain
[filter "lfs"]
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
    required = true
[credential]
    helper = manager
**[core]
    longpaths = true**