上下文
我正在编写一个脚本来镜像并定期刷新 GitHub 中的一些存储库。 GitHub 存储库引用了在外部没有任何意义的 pull 请求分支,因此我按照 Howto: Mirror a GitHub Repo Without Pull Refs 中的建议将它们过滤掉.到目前为止的步骤是
git clone --mirror SourceGitHubRepoUrl
git remote add --mirror=push alice MyMirrorUrl
git config --local --replace-all remote.origin.fetch "+refs/heads/*:refs/heads/*"
git config --local --add remote.origin.fetch "+refs/tags/*:refs/tags/*"
此时本地镜像有正确的抓取规则和
git remote update origin
效果很好,但是
git push --mirror alice
给出类似 的错误! [远程拒绝] refs/pull/22/head -> refs/pull/22/head
因为 packed-refs
仍然列出 refs/pull/*
分支机构。
问题
如何修复 packed-refs
的内容?我可以简单地删除所有匹配“refs/pull”的行吗?
后者似乎可行,但人们永远无法确定是否没有潜伏的小 Sprite 。
最佳答案
在类似的情况下,我能够使用 git-update-ref 通过裸仓库将远程
和 origin
增量更新到镜像远程 backup
git-pack-refs
:
git fetch --all --prune
BRANCHES="$(git branch --remotes | grep origin/ )"
for BRANCH in $BRANCHES; do
echo "--> setting local branch ${BRANCH#origin/} to remote branch ${BRANCH}"
git update-ref "refs/heads/${BRANCH#origin/}" $(git rev-parse $BRANCH)
git pack-refs --all
done
echo "--> pushing to backup"
git push --mirror backup
关于git - 如何重建 packed-refs 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28044784/