删除远程分支

Hos*_*250 8 c# libgit2sharp

我需要删除一个远程分支,并发现这种技术:

git push origin:the_remote_branch

我尝试以下列形式将它传递给Networks Push方法,但似乎没有任何工作(options是我的登录凭据):

_repo.Network.Push(_repo.Network.Remotes["origin"], "origin/:NewBranchForDeletion", options)  
_repo.Network.Push(_repo.Network.Remotes["origin"], ":NewBranchForDeletion", options)  
_repo.Network.Push(_repo.Network.Remotes["origin"], ":origin/NewBranchForDeletion", options)
_repo.Network.Push(_repo.Network.Remotes["origin"], ":refs/remotes/:origin/NewBranchForDeletion", options)
_repo.Network.Push(_repo.Network.Remotes["origin"], ":refs/remotes/origin/NewBranchForDeletion", options)
_repo.Network.Push(_repo.Network.Remotes["origin"], "refs/heads/:origin/NewBranchForDeletion", options)
_repo.Network.Push(_repo.Network.Remotes["origin"], "refs/heads/:NewBranchForDeletion", options)
Run Code Online (Sandbox Code Playgroud)

还有其他一些选择.我根本无法工作,它会返回错误,例如(对于":NewBranchForDeletion"方法):

不是有效的参考"NewBranchForDeletion"

更新:

感谢@Rob在LibGit2Sharp的回购中发现了这条评论:https://github.com/libgit2/libgit2sharp/issues/466#issuecomment-21076975

第一个选项失败,NullReferenceException启用了on objectish,并在上面提到的错误中使用string.Emptyobjectish结果.第二个选项是我正在尝试的,除了我使用的是HTTPS验证版本:

repo.Network.Push(repo.Remotes["my-remote"], objectish: null, destinationSpec: "my-branch");

// Or using a refspec, like you would use with git push...
repo.Network.Push(repo.Remotes["my-remote"], pushRefSpec: ":my-branch");
Run Code Online (Sandbox Code Playgroud)

nul*_*ken 5

文档中所述,refspec "Specif(ies) 用什么源对象更新什么目标 ref。<refspec> 参数的格式是一个可选的加号+,后跟源对象 <src>,后跟一个冒号:,后跟目标引用 <dst>。”

它还提到“推送一个空的 <src> 允许您从远程存储库中删除 <dst> 引用。”

上述考虑到这些,使用void Push(Remote remote, string pushRefSpec)过载,并通过:refs/heads/branch_to_deletepushRefSpec应该做的伎俩。