Git | windows上遇到特殊字符的问题
2023-08-08
参加了每日CSAPP
阅读会,拉取https://github.com/ArkTicketTech/CSAPP-Everyday的时候
仓库里有文件和文件夹包含特殊字符:
,只有在windows
上行不通,好像还有其他特殊字符和保留字段,
直接clone
的话,是行不通的
$ git clone https://github.com/ArkTicketTech/CSAPP-Everyday
Cloning into 'CSAPP-Everyday'...
remote: Enumerating objects: 20600, done.
remote: Counting objects: 100% (5084/5084), done.
remote: Compressing objects: 100% (2591/2591), done.
remote: Total 20600 (delta 2489), reused 4944 (delta 2398), pack-reused 15516
Receiving objects: 100% (20600/20600), 195.55 MiB | 4.72 MiB/s, done.
Resolving deltas: 100% (9061/9061), done.
error: invalid path 'homeworks/2023/2/2/holiday-2023:1:2/holiday-2023:1:2.md'
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'
git
会自动把所有文件删除(除了.git
),放入暂存区
问了大佬,尝试把这几个特殊文件放入.gitignore
中
把其余文件restore
后,特殊文件一直保留在暂存区,看着很不爽,有两个问题
- 如果不小心把特殊文件提交,那么
reset
也不管用,会一直报invalid path
- 如果一直忽略,当再次
pull
时,会遇到奇怪的问题,特殊文件从暂存区消失,会替换为另外两个正常的文件,且这两个文件不能被restore
决定再次尝试一下sparse,看了官方文档https://git-scm.com/docs/git-sparse-checkout,成功了
Inasa@Inasa-Windows11 MINGW64 ~/Desktop/tmp1
$ git clone --sparse -c core.protectNTFS=false -n https://github.com/ArkTicketTech/CSAPP-Everyday.git
Cloning into 'CSAPP-Everyday'...
remote: Enumerating objects: 20600, done.
remote: Counting objects: 100% (5084/5084), done.
remote: Compressing objects: 100% (2592/2592), done.
remote: Total 20600 (delta 2488), reused 4944 (delta 2397), pack-reused 15516Receiving objects: 100% (20600/20600), 193.77 MiB | 7.55 MiB/s
Receiving objects: 100% (20600/20600), 195.55 MiB | 7.46 MiB/s, done.
Resolving deltas: 100% (9058/9058), done.
Inasa@Inasa-Windows11 MINGW64 ~/Desktop/tmp1
$ git sparse-checkout set --no-cone '/*' '!homeworks/2023/2/2/*'
fatal: not a git repository (or any of the parent directories): .git
Inasa@Inasa-Windows11 MINGW64 ~/Desktop/tmp1
$ cd CSAPP-Everyday/
Inasa@Inasa-Windows11 MINGW64 ~/Desktop/tmp1/CSAPP-Everyday (main|SPARSE)
$ git sparse-checkout set --no-cone '/*' '!homeworks/2023/2/2/*'
Inasa@Inasa-Windows11 MINGW64 ~/Desktop/tmp1/CSAPP-Everyday (main|SPARSE)
$ git sparse-checkout list
/*
!homeworks/2023/2/2/*
Inasa@Inasa-Windows11 MINGW64 ~/Desktop/tmp1/CSAPP-Everyday (main|SPARSE)
$ git checkout main
Updating files: 100% (4428/4428), done.
Already on 'main'
Your branch is up to date with 'origin/main'.
Inasa@Inasa-Windows11 MINGW64 ~/Desktop/tmp1/CSAPP-Everyday (main|SPARSE)
$ ls
checkin.py create.sh homeworks/ LICENSE package.json package-lock.json readers.txt README.md textbooks/
- https://git-scm.com/docs/git-sparse-checkout
- OPENAI
- https://stackoverflow.com/questions/63727594/github-git-checkout-returns-error-invalid-path-on-windows
- https://github.com/bcgov/wps/issues/2605
- https://stackoverflow.com/questions/61614004/cloning-succeded-but-checkout-failed-due-to-invalid-path-what-is-the-path-probl
- https://stackoverflow.com/questions/14326365/git-clone-ignoring-a-directory