【git】git clone 出现 Filename too long

文章讲述了在Windows系统中使用Git克隆仓库时遇到Filenametoolong错误的原因,这是由于Windows对文件名长度的限制。Git本身允许最长4096个字符的文件名,但WindowsGit版本受限于260字符。解决方法是通过在PowerShell或cmd中设置`gitconfig--systemcore.longpathtrue`来启用长路径支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. git clone 出现 Filename too long

Windows 默认不支持文件名或目录名长于260个字符的,这个涉及到Windows资源管理器、命令行、GitHub客户端以及很多其它应用。所以Git的Windows客户端默认是禁用长名称支持的。
git clone 时出现以下错误:

$ git clone http://ip:port/xxx/xxxxxx.git
Cloning into 'xxxxxx'...
remote: Enumerating objects: 2036, done.
remote: Counting objects: 100% (2033/2033), done.
remote: Compressing objects: 100% (1300/1300), done.
remote: Total 2036 (delta 449), reused 2021 (delta 446), pack-reused 3
Receiving objects: 100% (2036/2036), 2.94 MiB | 4.70 MiB/s, done.
Resolving deltas: 100% (449/449), done.
fatal: cannot create directory at 'xxxx/xxx/xxxxx/xxxxx/xxxxx/xxxxxx': Filename too long
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'

这个文件名(或路径)是超过260个字符的,Git对文件名限制4096个字符,但是由于Windows版本的Git是使用msys编译的。它使用了旧版本的Windows Api,导致它限制文件名不能超过260个字符。

解决方案

打开Powershell或者cmd.exe(你需要将git添加到环境变量中)并执行下面的命令:

git config --system core.longpaths true

在这里插入图片描述
然后就可以去成功git了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

略安静一姑娘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值