【发布时间】:2016-03-03 05:12:38
【问题描述】:
我需要删除一个远程分支,发现了这个技巧:
git 推送来源: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)
还有其他一些选择。我根本无法让它工作,它返回诸如(对于“:NewBranchForDeletion”方法)之类的错误:
不是有效的参考“NewBranchForDeletion”
更新:
感谢@Rob 在 LibGit2Sharp 的 repo 上找到我这条评论:https://github.com/libgit2/libgit2sharp/issues/466#issuecomment-21076975
第一个选项在objectish 上出现NullReferenceException 失败,并且将string.Empty 用于objectish 会导致上述错误。第二个选项是我正在尝试的,除了我使用的是带有 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) -
哎呀,复制/粘贴错误。
-
或者,您有非删除推送的有效解决方案吗?模仿
git push origin dev:master的东西? -
是的。
_repo.Network.Push(branch, options);嗯,我试试看。 -
您是否考虑过
public virtual void Push(Remote remote, string pushRefSpec)过载?传递:refs/heads/branch_to_deleterefspec 应该可以工作。
标签: c# libgit2sharp