windows下git clone/checkout失败问题整理

问题1: 文件名和目录名太长导致git clone失败

解决: 刚开始查觉得应该是windows对目录长度有限制,查了后发现是260个字符。

1、文件名长度最大为255个英文字符,其中包括文件扩展名在内。一个汉字相当于两版个英文字符。
2、文件的全路径名长度最大为260个英文字符,包含扩展名在内。如路径为C:\Program Files\filename.txt,那么这28个字符都包含在此字符数值中。一个汉字相当于两个英文字符。

后面发现居然只需要改下git配置就能搞定,不多说,上命令

git config --system core.longpaths true

问题2: 如何解决windows下的大小写问题导致的clone warning

$ git clone ssh://ehaiyag@gerritslave.sero.gic.ericsson.se:29418/msp/systemtest.git
Cloning into 'systemtest'...
remote: Counting objects: 127, done
remote: Finding sources: 100% (101/101)
remote: Getting sizes: 100% (91/91)
remote: Compressing objects: 100% (710263/710263)
remote: Total 103406 (delta 35), reused 103305 (delta 0)
Receiving objects: 100% (103406/103406), 1.55 GiB | 7.69 MiB/s, done.
Resolving deltas: 100% (83467/83467), done.
Updating files: 100% (16617/16617), done.
warning: the following paths have collided (e.g. case-sensitive paths
on a case-insensitive filesystem) and only one from the same
colliding group is in the working tree:
<忽略......>

解决方法1: windows上打开WSL,在linux模式下对该文件夹打开case insensitive模式,太复杂不好搞,弃之.................
解决方法2: 在git下直接用 git update-index --assume-unchanged xxxx命令强制忽略,但可能切换branch的时候又会出现该问题,需要重新一个一个文件忽略,试着用下面这条指令搞定。
for i in $(git status | grep modified |awk '{print $2}'); do git update-index --assume-unchanged $i; done

问题3: 如何解决windows下因为文件名不支持导致checkout失败问题

$ git checkout master
error: invalid path 'NSTtests/dpiregression/etc/config/cups/PCPB-10269_UNSOLICITED_TRAFFIC/pdrs/app_unsolicited-app_ipv6_net_addr_2001:dba::b3-app_ipv6_net_addr_2001:dba::c4.yml'
error: invalid path 'NSTtests/dpiregression/etc/config/cups/PCPB-10269_UNSOLICITED_TRAFFIC/pdrs/app_unsolicited-app_net_ipv6_2001:dba::c4.yml'
error: invalid path 'NSTtests/dpiregression/etc/config/cups/PCPB-10269_UNSOLICITED_TRAFFIC/static/unsolicited-ipv6_net_addr_2001:dba::b3-ipv6_net_addr_2001:dba::c4-different_app.xml'
error: invalid path 'NSTtests/dpiregression/etc/config/cups/PCPB-10269_UNSOLICITED_TRAFFIC/static/unsolicited_and_net_ipv6_2001:dba::c4_different_app.xml'
error: invalid path 'NSTtests/dpiregression/etc/config/cups/session/PCPB-714_TcpOpts/createSessionName_fda3:dad7:9842:16::1e:956e.yml'

上面提示是由于这几个文件的用ipv6的冒号命名文件导致git checkout 失败。
解决方法:
git config core.protectNTFS false
查了下官方手册,官方原话: If set to true, do not allow checkout of paths that would cause problems with the NTFS filesystem

大概意思是说NTFS有个路径保护机制,防止文件系统出错。

完美搞定!!! 收工

posted @   无知是恶  阅读(4984)  评论(1编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示