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 @ 2020-11-19 16:45  无知是恶  阅读(4261)  评论(0编辑  收藏  举报