为什么第二次执行git fetch需要这么长时间?

问题描述 投票:0回答:1

我的项目仓库非常大,开发了6年多,有3~4G的git历史记录。如果第一次拉代码需要很长时间,我可以理解。

最近,我遇到了一个问题。当我第一次执行下面的命令时,很快就完成了。但是当我在短时间内第二次执行时,就花了很多时间

我的命令:

git fetch --no-tags --force --progress --depth=1 -- [email protected]:ipc/hj_app.git "+refs/heads/*:refs/remotes/origin/*"

首次控制台:

xxx@xxxMac-mini hj_app % git fetch --no-tags --force --progress --depth=1 -- [email protected]:ipc/hj_app.git "+refs/heads/*:refs/remotes/origin/*"
remote: Enumerating objects: 56, done.
remote: Counting objects: 100% (56/56), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 6 (delta 4), reused 2 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), 609 bytes | 304.00 KiB/s, done.
From code.wexx.com:ipc/hj_app
 * [new branch]              dev-ignoreAnyway-20240911-test1 -> origin/dev-ignoreAnyway-20240911-test1

第二次控制台:

xxx@xxxMac-mini hj_app % git fetch --no-tags --force --progress --depth=1 -- [email protected]:ipc/hj_app.git "+refs/heads/*:refs/remotes/origin/*"
remote: Enumerating objects: 287000, done.
remote: Counting objects: 100% (241941/241941), done.
remote: Compressing objects: 100% (123158/123158), done.
Receiving objects:  36% (84098/231341), 23.28 MiB | 3.33 MiB/s

第一次 git fetch 完成后,如果 git 服务器上没有新的变化,第二次 git fetch 就会出现问题。如果 git 服务器上有新的分支或标签,第二次 git fetch 会非常快。

下载完成后,发现.git/objects/pack中添加了一个文件,大约3.1G。看来长下载是为了这个文件。但为什么会被下载呢?如何避免下载?

更新:git 版本 2.39.3 (Apple Git-145)

添加一些背景知识,我第一次在 CI/CD (Jenkins) 中遇到这个问题。我可以在本地环境中重现这个问题

git
1个回答
0
投票

您已经截断了第二次提取的输出,但它显示了许多、很多更多的对象正在被提取。当您运行第二次提取时,上游可能没有任何新创建的历史记录,但有新引用的历史记录与您要求它查看的提示相匹配。这段历史到底是什么,Git 在您的问题中未包含的提取输出部分中告诉您,就像它告诉您它在第一个中提取的一个分支提示一样。

© www.soinside.com 2019 - 2024. All rights reserved.