Run git commands from a C# function

前端 未结 6 692
面向向阳花
面向向阳花 2020-12-14 08:02

How can my C# code run git commands when it detects changes in tracked file? I am writing a VisualStudio/C# console project for this purpose.

I am new to the the .N

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 08:46

    If you want to do it in C#, you can call the external git command by Process.Start when you detect file change

    string gitCommand = "git";
    string gitAddArgument = @"add -A";
    string gitCommitArgument = @"commit ""explanations_of_changes""";
    string gitPushArgument = @"push our_remote";
    
    Process.Start(gitCommand, gitAddArgument);
    Process.Start(gitCommand, gitCommitArgument);
    Process.Start(gitCommand, gitPushArgument);
    

    Not the best solution but it works in C#

提交回复
热议问题