我遇到了一个奇怪的问题,当我试图将更改从我的本地存储库推送到远程存储库时,有时(而且这种情况经常发生),git 表现得好像现有的分支没有被识别,它会尝试推送所有对象(超过 20.000 个),甚至我只对其中的 2 个对象进行了更改,并且状态为 00000000000000000000000000000000000000000
示例:
me@my-desktop:~/repo/project/$ git push origin feature/myFeature
Fetching remote heads...
refs/
refs/tags/
refs/heads/
refs/heads/feature/
updating 'refs/heads/feature/myFeature'
from 0000000000000000000000000000000000000000
to 161612d12a7a474fda294036e34c268131dbcb04
sending 21322 objects
更新:我使用 git flow 和分支功能。
最佳答案
假设您正在使用 http 推送(使用 DAV),我在 git 源的 http-push.c 中注意到以下内容:
/*
* NEEDSWORK: remote_ls() ignores info/refs on the remote side. But it
* should _only_ heed the information from that file, instead of trying to
* determine the refs from the remote file system (badly: it does not even
* know about packed-refs).
*/
如果此评论准确无误,则问题在于远程打包了目标引用,并且(如评论所述)推送找不到引用,因此它发送了每个对象。
因此,作为Matija Nalis在评论中建议,接收方的 git gc
导致了问题。您可以通过在接收器上重新创建解压缩的 ref 来测试它:
cd (path to repo .git directory)
(verify that refs/heads/branch does not exist)
awk '$2 == "refs/heads/branch" { print $1 }' packed-refs
(将结果行写入 refs/heads/branch
,然后尝试推送)。
由于我没有使用web push,所以无法自行验证。
关于git - 推送导致大量对象推送的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19689663/