简体   繁体   English

从远程删除分支

[英]Delete a branch from Remote

This is regarding API of libgit2sharp Remote Fixture.这是关于 libgit2sharp Remote Fixture 的 API。

I know how to Delete a branch from Remote using Push RefSpec.我知道如何使用 Push RefSpec 从远程删除分支。 However, I wanna know how to do it using the API.但是,我想知道如何使用 API 来做到这一点。 I tried following example,我试过下面的例子,

Repo.Network.Push(Repo.Network.Remotes["origin"], objectish: null, destinationSpec: branchName);

I provided correct branchName (checked remote).我提供了正确的branchName (检查远程)。 However, I get,然而,我明白了,

Unhandled exception: System.ArgumentNullException: Value cannot be null. (Parameter 'objectish')
   at LibGit2Sharp.Core.Ensure.ArgumentNotNull(Object argumentValue, String argumentName) in D:\git_ws\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 24
   at LibGit2Sharp.Network.Push(Remote remote, String objectish, String destinationSpec) in D:\git_ws\libgit2sharp\LibGit2Sharp\Network.cs:line 273

related: https://github.com/libgit2/libgit2sharp/issues/466相关: https : //github.com/libgit2/libgit2sharp/issues/466

How to properly call Repo.Network.Push to delete a branch from remote.如何正确调用Repo.Network.Push从远程删除分支。

Out of curiosity I also tried the example from RemoteFixture.cs like this,出于好奇,我也像这样尝试了RemoteFixture.cs的示例,

var remoteBranchName = "origin/" + branchName;
Repo.Branches.Remove(remoteBranchName, true);

This doesn't throw any error.这不会引发任何错误。 However, it does nothing.然而,它什么也不做。 Branch still exists on remote.远程仍然存在分支。

Thank you.谢谢你。 :) :)

cc @Keith Dahlby抄送@Keith Dahlby

Can you use the Push method that just takes push refspecs?你可以使用只接受推送引用规范的 Push 方法吗?

public virtual void Push(
            Remote remote,
            string pushRefSpec,
            PushOptions pushOptions)

The push refspec to delete references is described under the "Deleting references section here:删除引用的推送 refspec 在此处的“删除引用”部分中进行了描述:

https://git-scm.com/book/en/v2/Git-Internals-The-Refspec https://git-scm.com/book/en/v2/Git-Internals-The-Refspec

and would be similar to:并且类似于:

:refs/heads/branch-to-delete

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM