我怎样才能从 GitHub 的 拉(也许也是 用力)一些文件夹?
我的意思是我需要.NET 的 API 来访问 C # ,而不是 Git 的 GUI。
我刚找到这个: http://www.eqqon.com/index.php/GitSharp
GitSharp 是一个针对 Dot 的 Git实现。Net Framework 和 Mono。它的目标是与原始 Git 完全兼容,并且是一个轻量级的库,用于那些基于 Git 作为对象数据库,或者以某种方式读取或操作存储库的酷应用程序。
然而,我所做的是编写一个简单的类库,通过运行子进程来调用 git 命令。
首先,为某些配置创建 ProcessStartInfo。
ProcessStartInfo gitInfo = new ProcessStartInfo(); gitInfo.CreateNoWindow = true; gitInfo.RedirectStandardError = true; gitInfo.RedirectStandardOutput = true; gitInfo.FileName = YOUR_GIT_INSTALLED_DIRECTORY + @"\bin\git.exe";
然后创建一个 Process 来实际运行该命令。
Process gitProcess = new Process(); gitInfo.Arguments = YOUR_GIT_COMMAND; // such as "fetch orign" gitInfo.WorkingDirectory = YOUR_GIT_REPOSITORY_PATH; gitProcess.StartInfo = gitInfo; gitProcess.Start(); string stderr_str = gitProcess.StandardError.ReadToEnd(); // pick up STDERR string stdout_str = gitProcess.StandardOutput.ReadToEnd(); // pick up STDOUT gitProcess.WaitForExit(); gitProcess.Close();
那么现在就由你来调用任何命令。
正如 James Manning 在当前接受的答案的评论中提到的,库 Libgit2Sharp是一个积极支持的项目,它提供了一个。用于 Git 的 NET API。