I made a C# console app that runs a few git commands to reset local changes. However, I get an error "Unlink of file failed. Should I try again?" because of console app is running during the process
That exe has to be run during the reset. In additionally, Git gc or git add GitDiscarder.exe did not work.
internal class Program
{
static string[] commands =
{
"git rm --cached -r .",
"git reset --hard",
"git rm .gitattributes",
"git reset .",
"git checkout ."
};
public static void Main(string[] args)
{
for (int i = 0; i < commands.Length; i++)
{
RunCommand(commands[i]);
}
Console.ReadLine();
}
static void RunCommand(string command)
{
Console.WriteLine("**** " + command + " ****");
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.Arguments = "/C " + command;
using (Process discardProcess = Process.Start(startInfo))
{
if (discardProcess != null)
{
string output = discardProcess.StandardOutput.ReadToEnd();
Console.WriteLine(output);
discardProcess.WaitForExit();
}
}
}
}
