"git push --mirror"无法推送某些参考,其他参考是否正确推送?

  • 本文关键字:参考 是否 其他 push git --mirror git
  • 更新时间 :
  • 英文 :


我正在两个系统之间迁移 git 存储库,我想知道当git push --mirror无法推送某些引用时,其他引用是否成功推送......

例如,我收到这样的 git 推送输出:

eaa296537..f8ee5c121  master -> master
- [deleted]             20200619.2.dev
- [deleted]             20200619.3.dev
* [new branch]          feature/mailing -> feature/mailing
* [new tag]             20200626.5.dev -> 20200626.5.dev
* [new tag]             20200626.6.dev -> 20200626.6.dev
! [remote rejected]     refs/pull/11/merge (The current action can only be performed by the system
! [remote rejected]     refs/pull/4/merge (The current action can only be performed by the system
! [remote rejected]     refs/pull/6/merge (The current action can only be performed by the system
error: failed to push some refs to 'https://dev.azure.com/TEST'

其他分支和标签是否实际被推送?

为什么会这样?

Azure 还将信息存储在引用中(我得到了这个线程的信息(。Azure 存储库将有关拉取请求的信息存储在只读引用中。

这意味着,如果你只是天真地从一个 GitHub 存储库中 git pull --mirror,然后尝试将 git push --mirror 到 Azure 存储库,那么你将得到你在问题中显示的错误。

溶液

您可以提取您真正需要的引用:特别是分支(refs/heads(,标签(refs/tags(和注释(refs/notes(。通过仅选择这些引用集,您将不会克隆私有的只读引用,也不会尝试将它们推送回其他存储库。

我希望这个脚本可以帮助你:

#!/bin/sh
set -eufo pipefail
if [ "$#" -ne 2 ]; then
echo "usage: $0 source_repo_url target_repo_url" >&2
exit 1
fi
SOURCE_URL="$1"
TARGET_URL="$2"
WORKDIR="$(mktemp -d)"
echo "Cloning from ${SOURCE_URL} into ${WORKDIR}..."
git init --bare "${WORKDIR}"
cd "${WORKDIR}"
git config remote.origin.url "${SOURCE_URL}"
git config --add remote.origin.fetch '+refs/heads/*:refs/heads/*'
git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
git config --add remote.origin.fetch '+refs/notes/*:refs/notes/*'
git config remote.origin.mirror true
git fetch --all
echo ""
echo "Cloned to ${WORKDIR}; pushing to ${TARGET_URL}"
git push --mirror "${TARGET_URL}"
echo ""
echo "Cleaning up temporary directory ${WORKDIR}..."
rm -rf "${WORKDIR}"
echo "Done."

基于文章的答案:https://www.edwardthomson.com/blog/mirroring_git_repositories.html

是的:git push(或git fetch,就此而言(的输出表明您希望引用被接受和被拒绝。

(Git 总是可以出于任何它喜欢的原因拒绝一些 refspec。 在这种情况下,看起来您正在推送到 GitHub,并且他们保留所有refs/pull/名称。 分支和标记名称位于refs/heads/refs/tags/空间中,因此不会阻止分支或标记更新。

最新更新