为什么不使用通过进程运行的 GIT?喜欢
Process proc = new Process();
proc.StartInfo.FileName = @"git";
proc.StartInfo.Arguments = string.Format(@"clone ""{0}"" ""{1}""", repository_address, target_directory);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForInputIdle();
我认为这应该有效。但我也可能是错的。:)
编辑:设置用户凭据
// Create process
Process proc = new Process();
proc.StartInfo.FileName = @"*your_git_location*\\git-bash.exe";
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
// Wait for it to run
proc.WaitForInputIdle();
// Set up user name
proc.StandardInput.WriteLine("git config user.name ""your_user_name""");
proc.WaitForInputIdle();
// Set up user email
proc.StandardInput.WriteLine("git config user.email ""your_user_email""");
proc.WaitForInputIdle();
// Request clone of repository
proc.StandardInput.WriteLine(string.Format(@"git clone ""{0}"" ""{1}""", repository_address, target_directory););
proc.WaitForInputIdle();
// Now git should ask for your password
proc.StandardInput.WriteLine("your_password");
proc.WaitForInputIdle();
// Now clone should be complete
proc.Dispose();
这应该有效,我还没有测试过,可能还有一些语法错误,但我相信你会弄清楚的。关于 GIT 中的身份验证,可以使用称为凭据助手的功能以某种方式存储凭据,但我不确定如何设置它。我认为这个问题是一个好的开始,尝试从那里研究:
在 GitHub 上使用 https:// 时,有没有办法跳过密码输入?