簡體   English   中英

如何從git鏡像克隆中排除拉取請求

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

我想鏡像克隆一個Bitbucket存儲庫到另一個Bitbucket存儲庫。 我用shell腳本管理它,它執行以下操作:

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

現在我在推送時遇到以下錯誤,因為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 '...'

我通過使用以下解決方法調整fetch refs,從http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html解決了問題。

我創建了一個新的裸存儲庫,並按以下方式調整配置:

[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,一切都很好。

然而,變通方法並不是一個漂亮的解決方案,因為創建一個空的裸存儲庫,然后覆蓋它是很奇怪的,所以我想要一個替代方案。

問題:

  • 我可以使用“git clone --config”添加所需的獲取配置(在git clone執行初始獲取之前)但是我可以使用“git clone”命令刪除原始的fetch = +refs/*:refs/*配置嗎? 這將解決最初拉取拉請求的問題
  • 拉動后是否可以從裸存儲庫中刪除拉取請求?
  • 是否可以從推送中排除拉取請求?

感謝伊萬。

他的命令解決了我的問題。 我只需要將“-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