gpt4 book ai didi

git push 失败,除非我先在远程 repo 上执行 gc

转载 作者:太空狗 更新时间:2023-10-29 13:23:39 26 4
gpt4 key购买 nike

我在我的 Windows 7 机器上使用 git,推送到 Server 2008 机器上的共享文件夹。这在过去 6 个月里一直运行良好。但是,从昨天开始,我无法再推送到远程仓库。每次尝试时,我都会得到以下信息:

$ git push
Counting objects: 39, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (23/23), done.
Writing objects: 100% (23/23), 8.42 KiB, done.
Total 23 (delta 15), reused 0 (delta 0)
Unpacking objects: 100% (23/23), done.
error: Couldn't set refs/heads/my-branch
To //my-server/Code/my-project.git
! [remote rejected] my-branch -> my-branch (failed to write)
error: failed to push some refs to '//my-server/Code/my-project.git

在谷歌上搜索“无法推送某些引用”错误会给出各种结果,比如没有先 pull (我完全是最新的),并且没有正确的权限(我可以完全访问所有内容,并且可以创建/删除/通过资源管理器编辑远程仓库中的文件)。

然后我偶然发现了这篇博文 http://henke.ws/post.cfm/error-failed-to-push-some-refs其中提到您可能必须在远程存储库上运行一些清理命令。所以我在远程存储库上运行了 git gc:

$ git gc
Counting objects: 3960, done.
Compressing objects: 100% (948/948), done.
Writing objects: 100% (3960/3960), done.
Total 3960 (delta 2971), reused 3942 (delta 2964)

你看,我又可以 push 了!

$ git push
Counting objects: 39, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (23/23), done.
Writing objects: 100% (23/23), 8.42 KiB, done.
Total 23 (delta 15), reused 0 (delta 0)
Unpacking objects: 100% (23/23), done.
To //my-server/Code/my-project.git
8153afd..1385d28 my-branch -> my-branch

但问题是,我现在必须在远程存储库上运行 gc 每次我想进行推送。如果我不这样做,我会再次收到“无法推送某些引用”错误。

那么,为什么我的 repo 如此失败?我怎样才能永久解决这个问题?

最佳答案

看来您是在通过 Windows 网络共享进行推送,而不是使用 ssh 或 git 协议(protocol)。这意味着您的本地计算机必须将文件写入网络共享,因此可能会因任何锁定的文件或与该服务器相关的权限问题而受阻。

推送分支时,写入对象后,git 将通过写入文件 .git/refs/heads/my-branch 来更新分支的 ref。您的客户端目前似乎无法写入该文件。

当你执行 gc 时,refs 从 refs 目录中的松散文件中收集并放入文本文件 .git/packed-refs 中,然后删除各个 ref 文件。

我的理论是,当 ref 作为服务器上的松散文件存在时,您的推送失败,因为您无权覆盖现有文件,但您有创建新文件的权限。用 gc 打包 refs 后,ref 文件不再存在,因此您可以再次推送一次。

我建议的修复是:

  1. 验证您是否可以从客户端覆盖现有文件,如果不能则修复权限或文件锁定问题
  2. 切换到使用 git 协议(protocol),此博客似乎很好地概述了适用于 Windows 的选项 http://freshbrewedcode.com/derekgreer/2012/02/19/hosting-a-git-repository-in-windows/

作为最后的手段,如果您发现自己无法使用 gc 选项,您可以尝试运行“git pack-refs -all”。这比每次都用 gc 解决问题要快。

关于git push 失败,除非我先在远程 repo 上执行 gc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12321893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com