在拉取git项目过大时,遇到下面错误:
D:\Work>git clone <git-url>
Cloning into 'demo'...
remote: Enumerating objects: 197190, done.
remote: Counting objects: 100% (584/584), done.
remote: Compressing objects: 100% (538/538), done.
error: 32593 bytes of body are still expectedGiB | 11.68 MiB/s
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
方法一:
从使用HTTPS克隆换成使用 SSH 克隆。
方法二:
1.--depth=1:
表示只克隆最近一次提交的历史记录,不包含其他提交记录
git clone --depth=1 <git@gitlab.com/xxx.git> xxxx
git branch -r
origin/HEAD -> origin/master
origin/master
查看目前分支只有master
2.
git remote set-branches origin * // 用于设置远程仓库的分支,将远程仓库的所有分支都设置为本地仓库的跟踪分支
git config --get remote.origin.fetch // 用于获取远程仓库的默认抓取行为配置
git fetch --depth=1 origin test // 用于从远程仓库的test分支上抓取最新的提交记录,但只抓取最近一次提交的历史记录,不包含其他提交记录。
3.
git checkout -b test origin/test // 用于创建一个新的分支并切换到该分支
运行示例:
D:\>git clone --depth=1 <git-url>
Cloning into 'demo'...
remote: Enumerating objects: 4004, done.
remote: Counting objects: 100% (4004/4004), done.
remote: Compressing objects: 100% (3112/3112), done.
remote: Total 4004 (delta 939), reused 2719 (delta 422), pack-reused 0
Receiving objects: 100% (4004/4004), 58.68 MiB | 6.10 MiB/s, done.
Resolving deltas: 100% (939/939), done.
Updating files: 100% (3953/3953), done.
D:\>cd demo
D:\demo>git branch -r
origin/HEAD -> origin/master
origin/master
D:\demo>git remote set-branches origin *
D:\demo>git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
D:\demo>git fetch --depth=1 origin fixSso
remote: Enumerating objects: 320, done.
remote: Counting objects: 100% (320/320), done.
remote: Compressing objects: 100% (151/151), done.
remote: Total 174 (delta 119), reused 54 (delta 14), pack-reused 0
Receiving objects: 100% (174/174), 11.45 MiB | 2.96 MiB/s, done.
Resolving deltas: 100% (119/119), completed with 114 local objects.
From <git-url>
* branch fixSso -> FETCH_HEAD
* [new branch] fixSso -> origin/fixSso
D:\demo>git branch -r
origin/HEAD -> origin/master
origin/fixSso
origin/master
D:\demo>git checkout -b fixSso origin/fixSso
branch 'fixSso' set up to track 'origin/fixSso'.
Switched to a new branch 'fixSso'
方法三:
当你使用 --depth
标志克隆项目时,Git 会默认使用 --single-branch
标志。可以使用 --no-single-branch
标志告诉 Git 从每个分支拉取指定深度的历史记录。
1.
git clone --depth=1 --no-single-branch <git-url> xxx
运行示例:
D:\>git clone --depth=1 --no-single-branch <git-url> demo
Cloning into 'demo'...
remote: Enumerating objects: 49971, done.
remote: Counting objects: 100% (49971/49971), done.
remote: Compressing objects: 100% (25808/25808), done.
remote: Total 49971 (delta 33043), reused 35321 (delta 20462), pack-reused 0
Receiving objects: 100% (49971/49971), 1.61 GiB | 5.25 MiB/s, done.
Resolving deltas: 100% (33043/33043), done.
Updating files: 100% (3953/3953), done.
D:\>cd demo
D:\demo>git branch -r
origin/1013_branch
origin/1273bugFix
origin/20221014
origin/20221017
origin/2023.7.10.mch
origin/20230208
origin/20230213
origin/20230309
origin/20230310
origin/20230313
origin/20230320
origin/20230321
origin/20230323
origin/20230403_Camellia
origin/20230410_camellia
origin/20230412_camellia
origin/20230418_FIXBUG
origin/20230508_camelia
origin/20230518_camelia
origin/20230612_camelia
origin/20230721_camelia
origin/20230726_camelia
2.
git config --get remote.origin.fetch
3.
git checkout -b test origin/test
运行示例:
D:\Work\demo>git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
D:\Work\demo>git checkout -b fixSso origin/fixSso
branch 'fixSso' set up to track 'origin/fixSso'.
Switched to a new branch 'fixSso'