C#仅执行某些Git进程

时间:2018-08-24 17:42:35

标签: c# git

我正在尝试从C#应用程序运行git命令。由于某些原因,提取以及pull命令均不起作用(如果我将参数更改为tag,它将标记当前分支)。目前,我正在从不同文件位置的同一存储库中推送一个提交,并运行该过程,但是使用tortoise git显示该存储库仍应是最新的。

目前,我正在这样创建一个过程:

ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.RedirectStandardError = true;
info.RedirectStandardOutput = true;
info.FileName = @"path/to/git/executable/git.exe"
info.UseShellExecute = false;
info.WorkingDirectory = "path/to/repo"
info.Arguments = "fetch";
Process fetchProcess = new Process();
fetchProcess.StartInfo = info;
fetchProcess.Start();
//output Standard Error and Standard Output here.
fetchProcess.WaitForExit();
fetchProcess.Close();

当我从shell运行命令时,它确实可以正常工作。 进程运行git命令时是否不获取当前检出的分支?我尝试运行“ fetch --all”错误,因此我不确定运行git进程是否存在分支困难。

1 个答案:

答案 0 :(得分:0)

无论出于什么原因,拥有git.exe的完整路径都是问题。一旦完成info.FileName = "git.exe"的操作,我就可以抓取和拉出。奇怪的是,我能够使用完整的git路径进行标记,但不能执行其他命令,但是现在很好。