简体   繁体   English

如何从git镜像克隆中排除拉取请求

[英]How can I exclude pull requests from git mirror clone

I want to mirror clone a Bitbucket Repository to another Bitbucket Repository. 我想镜像克隆一个Bitbucket存储库到另一个Bitbucket存储库。 I manage this with a shell script, which does the following: 我用shell脚本管理它,它执行以下操作:

git clone --mirror <sourceUrl>
git remote set-url --push origin <targetUrl>
git push --mirror

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): 现在我在推送时遇到以下错误,因为Bitbucket不允许推送拉取请求(在源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 '...'

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. 我通过使用以下解决方法调整fetch refs,从http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html解决了问题。

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>

Then I perform a Git Pull and Git Push and everything is fine. 然后我执行Git Pull和Git Push,一切都很好。

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. 然而,变通方法并不是一个漂亮的解决方案,因为创建一个空的裸存储库,然后覆盖它是很奇怪的,所以我想要一个替代方案。

Questions: 问题:

  • 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? 我可以使用“git clone --config”添加所需的获取配置(在git clone执行初始获取之前)但是我可以使用“git clone”命令删除原始的fetch = +refs/*:refs/*配置吗? 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? 是否可以从推送中排除拉取请求?

Thanks to Ivan. 感谢伊万。

His command solved my Problem. 他的命令解决了我的问题。 I only had to add the "-r" parameter to xargs to react on empty greps: 我只需要将“-r”参数添加到xargs以对空greps做出反应:

git show-ref | cut -d' ' -f2 | grep 'pull-request' | xargs -r -L1 git update-ref -d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM