【问题标题】:! [remote rejected] errors after mirroring a git repository! [远程拒绝] 镜像 git 存储库后的错误
【发布时间】:2016-03-19 19:54:24
【问题描述】:

我正在关注此文档: https://help.github.com/articles/duplicating-a-repository/

git clone --mirror https://github.com/exampleuser/repository-to-mirror.git

cd repository-to-mirror.git

git push --mirror https://github.com/exampleuser/mirrored

输出显示存储库作为镜像推送,但由于某种原因,我也收到了这些错误:

 ! [remote rejected] refs/pull/1/head -> refs/pull/1/head (deny updating a hidden ref)
 ! [remote rejected] refs/pull/1/merge -> refs/pull/1/merge (deny updating a hidden ref)

这些错误是什么?我可以假设存储库是镜像的吗?

【问题讨论】:

    标签: git repository mirror


    【解决方案1】:

    正如this issue 中所述,当您镜像一个已向其发出拉取请求的 GitHub 存储库时,就会发生这种情况。

    以“refs/pull”开头的引用是 GitHub 创建的合成只读引用 - 您无法更新(因此“清理”)它们,因为它们反映的分支很可能实际上是来自其他存储库 - 向您提交拉取请求的存储库。

    因此,虽然您推送了所有真实的 ref,但拉取请求不会得到更新

    您需要mirror a GitHub repo without their pull requests

    只需将上面的 catch-all refspec 替换为两个更具体的规范,只包含所有 head 和标签,但不包括 pulls,所有远程 pull refs 将不再进入您的裸镜像:

    fetch = +refs/heads/*:refs/heads/*
    fetch = +refs/tags/*:refs/tags/*
    fetch = +refs/change/*:refs/change/*
    

    如果推送仍然失败,如commented by Ofek Shilon,添加推送条目:

    push = +refs/heads/*:refs/heads/*
    push = +refs/tags/*:refs/tags/*
    push = +refs/change/*:refs/change/*
    

    正如Git Refspec中提到的:

    + 告诉 Git 更新引用,即使它不是快进。

    【讨论】:

    • 谢谢,我完成了这个过程,但由于某种原因,我仍然遇到同样的错误。我用 --mirror 克隆了 repo,我用 git config -e 编辑了 git 配置并运行 - git remote updategit push mirror 仍然得到同样的错误。
    • @deezx 什么返回git config --get-regex remote.origin.fetch
    • 这是输出 - $ git config --get-regex remote.origin.fetch remote.origin.fetch +refs/heads/*:refs/heads/* remote.origin.fetch +refs /tags/*:refs/tags/* 实际上,当我在没有 --mirror 的情况下克隆存储库时,按照您编写的方式编辑了 git 配置,它可以工作。它只获取分支和标签,所以它起作用了!我现在唯一的问题是我发现它没有反映refs/changes。有没有办法告诉 git 获取除拉取请求(refs/pull)之外的所有内容?
    • @deezx 不,您需要添加+refs/changes/*:refs/changes/* 才能获取headstagschanges,但不能获取pullgit push --mirror 在那之后可以工作吗?确保在新的本地克隆中重试(不是 clone --mirror,只是简单的克隆,在其中添加 fetch refspecs,执行 git fetch,然后将 push --mirror 到另一个 repo)
    • @OfekShilon 确实如此。我已经相应地更新了答案。
    【解决方案2】:

    而不是

    git clone --mirror

    使用

    git clone --bare

    instructions

    【讨论】:

    • 这是语义上的变化。这意味着他将无法推送到这个遥控器。
    【解决方案3】:

    (我希望这是评论,但声望不够)

    根据@VonC 的回答,这听起来不是问题。

    所以,虽然你已经推送了所有真实的 ref,但拉取请求并没有得到更新

    我看到您想要复制存储库的两种情况。

    1. 您想要一个您可以完全控制的存储库的备份/副本。
    2. 您正在修改存储库的历史记录,并且需要在本地进行备份,以防您需要撤消更改。

    在任何一种情况下,git clone --mirror 似乎都是您最安全的选择,因为即使您在push 中看到错误,所有与拉取请求相关的内容都已成功推送,这可以解决方案 1。对于在场景 2 中,您希望将这些拉取请求引用作为备份的一部分。

    【讨论】:

    • 我更多的是在 senario 2 中,我想完全迁移我的存储库(并且对保留任何拉取请求的历史很感兴趣)。我将如何解决保持它们完好无损的解决方案(即 github repo --> mirror clone --> gitlab(或其他 vcs))
    【解决方案4】:

    https://www.metaltoad.com/blog/git-push-all-branches-new-remote那里找到了可行且简单的解决方案

    git push newremote refs/remotes/oldremote/*:refs/heads/*
    

    git push newremote refs/remotes/oldremote/features/*:refs/heads/features/*
    

    【讨论】:

      【解决方案5】:

      完整步骤:

      git clone --bare https://github.com/exampleuser/old-repository.git
      cd old-repository
      git push --mirror https://github.com/exampleuser/new-repository.git
      

      【讨论】:

      • 哇,这应该是选择的答案!
      • 简单且 100% 工作
      【解决方案6】:

      在 fetch = +refs/:refs/ 行之后将这三行添加到 git 配置文件为我修复了它:

      push = +refs/heads/*:refs/heads/*
      push = +refs/tags/*:refs/tags/*
      push = +refs/change/*:refs/change/*
      

      【讨论】:

        猜你喜欢
        • 2014-01-12
        • 2014-07-05
        • 2013-11-28
        • 1970-01-01
        • 2021-01-10
        • 2022-06-21
        • 1970-01-01
        • 1970-01-01
        • 2020-03-12
        相关资源
        最近更新 更多