簡體   English   中英

GIT - 無法從遠程存儲庫中刪除特定分支

[英]GIT - unable to remove specific branch from remote repository

我無法刪除名為origin/featureBranch的遠程分支。 我想這是因為分支名稱以origin開頭,但我不確定:

$ git branch -r | grep featureBranch
  origin/origin/featureBranch

$ git push origin :origin/featureBranch

    error: unable to push to unqualified destination: origin/featureBranch

    The destination refspec neither matches an existing ref on the remote nor
    begins with refs/, and we are unable to guess a prefix based on the source ref.

    error: failed to push some refs to 'git@github.com:myCompany/my-repo.git'

UPDATE

$ git push origin :featureBranch給出了同樣的錯誤。

注意

在遠程分支中是origin/origin/myFeature ,本地它是origin/myFeature

我知道origin通常意味着什么,但在我的情況下 - 這是分支名稱的一部分。

Github沒有看到這個分支。


可以請任何人解釋我“幕后”發生了什么,我怎么能刪除這個分支?

嘗試這個:

git push origin :refs/heads/origin/featureBranch

您始終可以通過refs/heads/下的技術名稱引用分支。

分支存儲為.git/refs/下的小文本文件。 本地分支在.git/refs/heads/ ,遠程分支在.git/refs/remotes/<remotename>/ 因此可以在.git/refs/heads/master.git/refs/remotes/origin/master找到像master這樣的簡單分支,但是你的bug分支實際上將駐留在.git/refs/heads/origin/featureBranch 它不會與origin存儲庫上的遠程分支混淆,因為它不在refs/remotes/origin/ ,而是在refs/heads/

在遠程服務器上, origin/featureBranch分支是服務器的本地分支,因此它將存儲在refs/heads/ 當推送到給定分支時,您可以通過其名稱或路徑來識別它,因此如果名稱不起作用,只需使用以refs開頭的完整路徑。

你是如何結束這個奇怪的分支名稱的? 我無法確定,因為我不知道你做了什么,但是當我使用git push --mirror時,我遇到了同樣的問題,它推送了所有引用, 包括遠程引用,因此它將創建一個origin/branchname作為當地分支機構。

這應該工作:

$ git push origin :featureBranch

您已經指定了推送位置, origin/只是您本地分支的名稱。

背景:當git進行提取時,它會創建所謂的“遠程跟蹤分支”。 這些與您自己的分支沒有什么不同,它們只是以遠程名稱(例如origin / master)為前綴,並在本地表示服務器分支(所有提交都已被提取)。

當您執行推送源時,您根本不是指本地遠程跟蹤分支,而是告訴Git“推送到源sourcebranch:targetbranch”

消息的這一位說它找不到任何匹配的分支。

The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.

如果我嘗試刪除分支兩次,這就是我得到的。 (第一個成功,第二個失敗)。 或者如果分支已被其他人刪除。 你可以嘗試git remote prune ,看看它是否從你的git branch -r輸出中消失了。 您還可以使用git ls-remote git@github.com:myCompany/my-repo.git檢查分支是否在origin git ls-remote git@github.com:myCompany/my-repo.git

刪除奇怪的(嚴重?)命名分支,如origin/master on origin對我來說很好用:

$ git push origin master:origin/master
Counting objects: 3, done.
Writing objects: 100% (3/3), 218 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To ../bare/
 * [new branch]      master -> origin/master

$ git branch -r
  origin/origin/master

$ git push origin :origin/master
To ../bare/
 - [deleted]         origin/master

只需將origin放在冒號后面:

git push origin :featureBranch

正如邁克爾解釋的那樣,這意味着將“無所事事”推向命名分支。 是一個更完整的解釋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM