【问题标题】:Delete Remote Branch删除远程分支
【发布时间】: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_delete refspec 应该可以工作。

标签: c# libgit2sharp


【解决方案1】:

documentation 中所述,refspec “指定使用什么源对象更新什么目标 ref。 参数的格式是可选的加号+,后接源对象,后接冒号:,后接目标引用。"

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

考虑到以上这些,使用void Push(Remote remote, string pushRefSpec) 重载,并将:refs/heads/branch_to_delete 作为pushRefSpec 传递应该可以解决问题。

【讨论】:

    猜你喜欢
    • 2016-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-29
    • 2023-01-12
    • 2013-01-07
    相关资源
    最近更新 更多