LibGit2Sharp 获取远程存储库的最新版本

LibGit2Sharp Getting the last version of a remote repository

我想跟踪在我的 winforms 项目中使用 git 的项目。我不想克隆完整的存储库和完整的历史记录,我只想要最新版本,并且我希望能够从远程项目更新到新的修订版。

我试过了

co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = userName, Password = passWord };

        Repository.Clone("Git/repo", @tmpRepoFolder, co);

,但这会创建整个存储库的副本(巨大的文件大小),并且跟踪更改会使磁盘 space 变得更大(100mb 的文件现在占用超过 2gb)。

我不需要历史,也不需要标签。我只想要最新版本。

基本上你想要一个 shallow 克隆(相当于 git clone --depth 命令)实际上不支持,有一个开放的 issue 那个

作为替代方案,您可以使用 git 应用程序启动一个进程来执行您想要的操作。

举个例子:

using(System.Diagnostics.Process p = new Process())
{
    p.StartInfo = new ProcessStartInfo()
    {
        RedirectStandardInput = true,
        RedirectStandardOutput = true,
        UseShellExecute = false,
        FileName = @"C:\Program Files\Git\bin\git.exe",
        Arguments = "clone http://username:password@path/to/repo.git"  + " --depth 1"                
    };

    p.Start();
    string output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();
}