Ser*_*giu 5 c# git libgit2sharp
我想在本地和远程删除一个分支。我的代码:
using (var repository = new Repository(path))
{
var remote = repository.Network.Remotes["origin"];
var options = new PushOptions();
var credentials = options.CredentialsProvider = GetUserCredentialsProvider();
options.CredentialsProvider = credentials;
string pushRefSpec = @"refs/heads/:{0}".FormatWith(branch);
repository.Network.Push(remote, pushRefSpec);
repository.Branches.Remove(repository.Branches[branch]);
}
Run Code Online (Sandbox Code Playgroud)
但是我收到 401 错误(“未经授权”)。这是因为分支名称中存在“:”。
但是我读到它们是必要的,因为它们就像本机 git 中的“--delete”。
感谢您的帮助!
小智 3
由于未经授权,此操作失败并出现 401 未经授权错误。要修复此错误,您只需将options包含您的凭据的内容传递给该Push()方法:
repository.Network.Push(remote, pushRefSpec, options)
Run Code Online (Sandbox Code Playgroud)
这为我解决了这个问题。
| 归档时间: |
|
| 查看次数: |
1300 次 |
| 最近记录: |