我需要删除一个远程分支,并找到了以下操作:
git push origin :the_remote_branch
我尝试将其以以下形式传递给Network
s 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)
还有其他几个选项。我完全弄不好,它会返回错误,例如(对于“:NewBranchForDeletion”方法):
“NewBranchForDeletion”无效的引用
更新:
感谢@Rob在LibGit2Sharp的存储库中找到了这条评论:https://github.com/libgit2/libgit2sharp/issues/466#issuecomment-21076975
第一个选项在“objectish”上失败并引发NullReferenceException
,在objectish
上使用string.Empty
会导致上述错误。我正在尝试第二个选项,但我正在使用带有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");
Push
两次呢?在我看来,解决方案应该类似于Push(_repo.Network.Remotes["Origin"], "", "NewBranchForDeletion", options)
。 - Rob_repo.Network.Push(branch, options);
嗯,我会试试看。 - user2509848public virtual void Push(Remote remote, string pushRefSpec)
重载吗?传递一个:refs/heads/branch_to_delete
refspec 应该可以工作。 - nulltokenrefs/heads/:branch_to_delete
,但没有成功,我没想到还有这个选项。请把它作为答案发布。 - user2509848