git檢出新分支遇到的文件路徑過長Filename too long的問題

環境

git 2.18.0
TortoiseGit 2.8.0.0(64bit)
windows10 專業版

背景

由於hadoop2.x和hadoop3.x版本的代碼結構有很大不同,在查看有關監控的源碼發現不一致,爲了對比,checkout出hadoop3.1.0版本的源碼到本地報錯,報錯內容如下:

$ git checkout -f head
error: unable to create file hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-common/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/subapplication/SubApplicationColumnFamily.java: Filename too long
error: unable to create file hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-common/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/subapplication/SubApplicationColumnPrefix.java: Filename too long

解決步驟:
1、修改windows的文件路徑限制
window10左下角搜索“regedit”,發現“註冊表編輯器”,進入到路徑“計算機\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem”中,顯示界面的右邊雙擊“LongPathsEnabled”,將“數值數據”從“0”改爲“1”,確認退出。
在這裏插入圖片描述
2、windows10右下角“win”右鍵選擇“運行”,進入路徑“計算機配置\管理模板\系統\文件系統”,界面右側將“啓用Win32長路徑”的狀態修改爲“已啓用”。
在這裏插入圖片描述
3、進入到項目根路徑,打開git bash界面,執行命令

git config --global core.longpaths true

回車後生效

注意

1、執行第一步和第二步需要重啓電腦後生效
2、如果執行第三步報錯:

error: could not lock config file /pathto/file/.gitconfig: No such file or directory

嘗試了網上很多方法,無效,刪除整個項目文件然後重新clone項目後再執行第三步,不報錯誤,問題解決。

參考鏈接:

1、https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
2、https://stackoverflow.com/questions/22575662/filename-too-long-in-git-for-windows

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章