【问题标题】:How to fetch change from Git using LibGit2Sharp?如何使用 LibGit2Sharp 从 Git 获取更改?
【发布时间】:2014-02-25 11:07:13
【问题描述】:

下面的代码将一个 Git url 克隆到一个测试目录。

var url = @"http://abc-555.com/team/project-555.git";
var path = @"E:\temp_555";

var credential =  new Credentials() { Username = "a8888", Password="88888888"};
var clonePath = Repository.Clone(url, path, credentials: credential);

using (var repo = new Repository(clonePath))
{
    foreach (var branch in repo.Branches)
    {
        Console.WriteLine(branch.Name);
    }

    // somebody creates a new branch here, so I want to fetch it.
    repo.Fetch("origin");

    foreach (var branch in repo.Branches)
    {
        Console.WriteLine(branch.Name);
    }
}

我想在合并到本地 Git 之前获取一个新分支。无论如何,它会抛出An error was raised by libgit2. Category = Net (Error). Request failed with status code: 401 异常。

如何解决这个问题?

【问题讨论】:

    标签: c# .net git version-control libgit2sharp


    【解决方案1】:

    您可以通过 FetchOptions 实例指定要使用的凭据作为Fetch 调用的最后一个参数。

    repo.Fetch("origin", new FetchOptions { Credentials = credential});
    

    【讨论】:

    猜你喜欢
    • 2017-10-20
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多