GIT clone 项目报错

用git bash命令行clone项目时,报以下错误,说是代码中的某个文件名过长:Filename too long

$ git clone -b xxxxxxx_20181128xxx http://gitlab.xxxxxx-xxx.com/xxxxxxxx_release/xxxxxxxxxxxxx.git
Cloning into 'xxxxxxxxxxxxx'...
remote: Enumerating objects: 36742, done.
remote: Counting objects: 100% (36742/36742), done.
remote: Total 71414 (delta 1530), reused 29527 (delta 1530)B/s
Receiving objects: 100% (71414/71414), 29.57 MiB | 13.88 MiB/s, done.
Resolving deltas: 100% (6557/6557), done.
Checking connectivity... done.
error: unable to create file app/test/src/test/java/com/xxx/.../abcdefghigklmnopqrstuvwxyzbpmfdtn...lgkhjqxzcsywv1234567890aoeiuv.yaml: Filename too long
Checking out files: 100% (5663/5663), done.
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'

 

报错原因:git服务器的项目中有个文件的文件名过长,如上述日志中的:app/test/src/test/java/com/xxx/.../abcdefghigklmnopqrstuvwxyzbpmfdtn...lgkhjqxzcsywv1234567890aoeiuv.yaml,而:

git有可以创建4096长度的文件名,然而在windows最多是260,因为git用了旧版本的windows api。所以报错。

解决方案:在执行clone命令前,先执行下如下命令:

git config --global core.longpaths true

注意:该命令其实就是设置了一个对于windows系统的全局变量,可以用以下方式验证是否设置成功:

打开wins目录:C:\Users\admin(admin是wins的登陆用户),看该路径下是否有.gitconfig文件,打开如下即设置成功:

GIT clone 项目报错_第1张图片

再执行clone命令即可:

$ git clone -b xxxxxxx_20181128xxx http://gitlab.xxxxxx-xxx.com/xxxxxxxx_re                                                                                                                           lease/xxxxxxxxxxxxx.git
Cloning into 'xxxxxxxxxxxxx'...
remote: Enumerating objects: 71457, done.
remote: Counting objects: 100% (71457/71457), done.
remote: Total 71457 (delta 4842), reused 68337 (delta 4842)
Receiving objects: 100% (71457/71457), 31.27 MiB | 10.96 MiB/s, done.
Resolving deltas: 100% (4842/4842), done.
Checking connectivity... done.
Checking out files: 100% (5663/5663), done.

可以看到日志中不再报错,打开idea后亲测也可以与git正常连接。

你可能感兴趣的:(git,java后端面试)