如何从git mirror clone中排除拉取请求 [英] How can I exclude pull requests from git mirror clone
问题描述
我想将一个Bitbucket存储库镜像克隆到另一个Bitbucket存储库. 我使用外壳程序脚本对此进行管理,该脚本执行以下操作:
I want to mirror clone a Bitbucket Repository to another Bitbucket Repository. I manage this with a shell script, which does the following:
git clone --mirror <sourceUrl>
git remote set-url --push origin <targetUrl>
git push --mirror
现在,在推送时出现以下错误,因为Bitbucket不允许推送请求(在源Bitbucket上创建):
Now I'm getting the following error when pushing because Bitbucket does not allow to push pull requests (which are created on the Source Bitbucket):
remote: You are attempting to update refs that are reserved for Bitbucket's pull
remote: request functionality. Bitbucket manages these refs automatically, and they may
remote: not be updated by users.
remote:
remote: Rejected refs:
remote: refs/pull-requests/21/from
remote: refs/pull-requests/23/from
remote: refs/pull-requests/23/merge
remote: refs/pull-requests/24/from
remote: refs/pull-requests/24/merge
To ...
! [remote rejected] refs/pull-requests/21/from -> refs/pull-requests/21/from (pre-receive hook declined)
! [remote rejected] refs/pull-requests/23/from -> refs/pull-requests/23/from (pre-receive hook declined)
! [remote rejected] refs/pull-requests/23/merge -> refs/pull-requests/23/merge (pre-receive hook declined)
! [remote rejected] refs/pull-requests/24/from -> refs/pull-requests/24/from (pre-receive hook declined)
! [remote rejected] refs/pull-requests/24/merge -> refs/pull-requests/24/merge (pre-receive hook declined)
error: failed to push some refs to '...'
我从 http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html ,方法是采用以下变通方法来适应提取引用.
I solved the Problem with a Hint from http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html by adapting the fetch refs with the following workaround.
我创建了一个新的裸存储库,并通过以下方式修改了配置:
I created a new bare Repository and adapted the config the following way:
[core]
repositoryformatversion = 0
filemode = true
bare = true
[remote "origin"]
fetch = +refs/heads/*:refs/heads/*
fetch = +refs/tags/*:refs/tags/*
url = <sourceUrl>
mirror = true
pushurl = <targetUrl>
然后我执行Git Pull和Git Push,一切都很好.
Then I perform a Git Pull and Git Push and everything is fine.
尽管如此,解决方法也不是一个很好的解决方案,因为创建一个空的裸存储库然后将其覆盖是很奇怪的,所以我想要一个替代方法.
Nevertheless the Workaround is not a beautiful solution because creating an empty bare repository and then overwriting it is weird so I want an alternative.
问题:
- 我可以使用"git clone --config"添加所需的获取配置(在git clone执行其初始获取之前),但是我也可以使用"git clone"命令删除原始的
fetch = +refs/*:refs/*
配置吗?这将解决问题,即最初会拉出拉取请求" - 是否有可能在拉出之后从裸存储库中删除拉出请求?
- 是否可以从推送中排除推送请求?
- I can add the needed fetch Configuration with "git clone --config" (before git clone performs it's initial fetch) but can I remove the original
fetch = +refs/*:refs/*
Configuration also with the "git clone" Command? This would solve the problem, that the Pull Requests are pulled initially - Is it possible to remove the pull requests from the bare repository after the pull?
- Is it possible to exclude the pull requests from the push?
推荐答案
感谢Ivan.
他的命令解决了我的问题.我只需要在xargs上添加"-r"参数即可对空的greps做出反应:
His command solved my Problem. I only had to add the "-r" parameter to xargs to react on empty greps:
git show-ref | cut -d' ' -f2 | grep 'pull-request' | xargs -r -L1 git update-ref -d
这篇关于如何从git mirror clone中排除拉取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!