!镜像 git 存储库后出现 [remote rejected] 错误

! [remote rejected] errors after mirroring a git repository

我正在关注此文档: 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)

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

this issue 中所述,当您镜像 GitHub 存储库时会发生这种情况,该存储库已向其发出 拉取请求

The refs beginning 'refs/pull' are synthetic read-only refs created by GitHub - you can't update (and therefore 'clean') them, because they reflect branches that may well actually come from other repositories - ones that submitted pull-requests to you.

So, while you've pushed all your real refs, the pull requests don't get updated

您需要 mirror a GitHub repo without their pull requests

Simply replace the catch-all refspec above with two more specific specs to just include all heads and tags, but not the pulls, and all the remote pull refs will no longer make it into your bare mirror:

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

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

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

Git Refspec 中所述:

The + tells Git to update the reference even if it isn’t a fast-forward.

而不是

git克隆--镜像

使用

git克隆--裸机

instructions

(我想这是一个评论,但没有足够的声誉)

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

So, while you've pushed all your real refs, the pull requests don't get updated

我看到了两种情况,您想在其中复制存储库。

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

无论哪种情况,似乎 git clone --mirror 都是您最安全的选择,因为即使您在 push 中看到错误,所有与拉取请求无关的内容都已成功推送,这需要处理场景 1。对于场景 2,您希望将这些拉取请求引用作为备份的一部分。

在那里找到了可行且简单的解决方案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/*

完整步骤:

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

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

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