git clone - error: invalid path

概述

迁出一个git项目时, 出现以下报错.

error: invalid path 'Debugging-system:-ideas-on-how-to-improve-the-debugging-system.mediawiki'

这个库在远端服务器已经clone成功了, 这个文件可以浏览, 内容正常.
将远端库的.git Clone到本地时报错, 是不是文件路径太长了呢? 第一感觉就是这样.
本地的迁出路径为 D:\3rd_prj\contiki\contiki_wiki
已经够短的了, 没有必要再找一个根目录下的更短的路径来迁出.
查了网上的解决方法, 配置如下

git config --global core.protectNTFS false

还有一个换行转换的配置

git config --global core.autocrlf false

有点好奇, 这2个配置是啥? 去git官方(https://git-scm.com/docs/git-config)查了如下

core.protectNTFS

core.protectNTFS
If set to true, do not allow checkout of paths that would cause problems with the NTFS filesystem, e.g. conflict with 8.3 "short" names. Defaults to true on Windows, and false elsewhere.

core.protectNTFS 如果为true, 不允许迁出可能不符合NTFS系统路径的文件. 所以要设置为false, 原样从库里迁出.
因为windows中是可以设置文件有超长路径的, 这个也不应该由git迁出来考虑.

core.autocrlf

core.autocrlf
Setting this variable to "true" is the same as setting the text attribute to "auto" on all files and core.eol to "crlf". Set to true if you want to have CRLF line endings in your working directory and the repository has LF line endings. This variable can be set to input, in which case no output conversion is performed.

core.autocrlf 如果为true, 会将文件中的文本行的结尾’\0’换位"\r\n"
这个设置为false, 可以保证原样迁出, 不修改迁出的文件格式.
用TortoiseGit 2.13.0.1迁出, 项目可以迁出成功了. 不会报错.
在这里插入图片描述
但是超长的那个文件(Debugging-system:-ideas-on-how-to-improve-the-debugging-system.mediawiki), 其实还是迁出失败.
迁出后为 Debugging-system, size = 0
估计是这个文件的名称有windows不允许的字符, 而不仅仅是文件名超长的问题.
尝试在资源管理器中, 手工建立 Debugging-system:-ideas-on-how-to-improve-the-debugging-system.mediawiki
果然, 不能手工建立. 看了出错提示, 原来是这个文件名中有 ':'字符, 那就要怪开源作者了. 估计人家不是在windows中建立wiki工程的所以不报错.

在这里插入图片描述
现在可以在远端的git服务器, 将这个不符合windows文件格式的文件改名, 将’:'去掉
在这里插入图片描述
重新在本地迁出整个项目, 迁出成功了.
在这里插入图片描述
远端文件改名后,可能会引起迁出后的文件引用关系出错. 当出错时, 就引用自己改名后的这个文件.

备注

如果要考虑不同OS之间文件名的兼容性, 文件命名规则最好如下:

  • 最好只使用英文字母(大小写可以混合), 不要使用中文或者其他英文符号.
  • 如果要连接不同的词组描述, 最好使用’_’
  • 文件名称长度, 尽量短一些

END

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐