git - 推送导致大量对象推送的更改

标签 git

我遇到了一个奇怪的问题,当我试图将更改从我的本地存储库推送到远程存储库时,有时(而且这种情况经常发生),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/

相关文章:

linux - 可以在 Git bash 中使用的 Linux 终端命令列表有哪些?

Windows 上的 Git bash - 不支持 sftp

django - 如何将大型 Django 项目划分为子项目进行扩展?

git - 从项目的旧版本中恢复 git 历史记录

git - 通过 Git 将代码从一台计算机传输到另一台计算机

Git - 如果我想拥有一致的工作流程,那么 cherry-pick 是一种不好的做法吗?

git pre-push 钩子(Hook),如果是 --tags 则不要运行

git - 如何通过 1 次提交修复 "Your branch is ahead of ' origin/master'。”?

git 在 rebase 期间崩溃

git - 如何将非标准 svn 存储库克隆到 git?