LeoChen.GitHelper 1.0.2025.827

dotnet add package LeoChen.GitHelper --version 1.0.2025.827
                    
NuGet\Install-Package LeoChen.GitHelper -Version 1.0.2025.827
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LeoChen.GitHelper" Version="1.0.2025.827" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LeoChen.GitHelper" Version="1.0.2025.827" />
                    
Directory.Packages.props
<PackageReference Include="LeoChen.GitHelper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LeoChen.GitHelper --version 1.0.2025.827
                    
#r "nuget: LeoChen.GitHelper, 1.0.2025.827"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LeoChen.GitHelper@1.0.2025.827
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LeoChen.GitHelper&version=1.0.2025.827
                    
Install as a Cake Addin
#tool nuget:?package=LeoChen.GitHelper&version=1.0.2025.827
                    
Install as a Cake Tool

GitHelper

一个用于简化 Git 命令操作的 .NET 工具库,提供了对 Git 命令的封装,使在 .NET 应用中执行 Git 操作变得更加简单和直观。

特性

  • 简化 Git 命令执行
  • 提供面向对象的 API
  • 支持常用 Git 操作(clone、branch、checkout、merge、fetch、pull、push 等)
  • 支持超时控制
  • 支持异步操作
  • MIT 开源许可证

安装

目前可以通过以下方式使用本项目:

  1. 克隆项目源代码
  2. 将项目添加到你的解决方案中
  3. 添加项目引用

使用方法

基本用法

using LeoChen.GitHelper;

// 创建 GitProcessHelper 实例
var gitHelper = new GitProcessHelper(@"C:\path\to\your\repository");

// 执行 Git 命令
var result = gitHelper.Status();
if (result.Success)
{
    Console.WriteLine("Git 状态:");
    Console.WriteLine(result.Output);
}
else
{
    Console.WriteLine($"执行失败: {result.Error}");
}

克隆仓库

// 克隆远程仓库
var cloneResult = gitHelper.Clone("https://github.com/user/repo.git", @"C:\path\to\local\directory");
if (cloneResult.Success)
{
    Console.WriteLine("仓库克隆成功");
}

分支操作

// 获取所有本地分支
var localBranches = gitHelper.GetLocalBranch();
foreach (var branch in localBranches)
{
    Console.WriteLine($"本地分支: {branch}");
}

// 获取所有远程分支
var remoteBranches = gitHelper.GetRemoteBranch();
foreach (var branch in remoteBranches)
{
    Console.WriteLine($"远程分支: {branch}");
}

// 获取当前分支
var currentBranch = gitHelper.GetCurrentBranch();
Console.WriteLine($"当前分支: {currentBranch}");

提交操作

// 添加文件到暂存区
gitHelper.Add(".");

// 提交更改
var commitResult = gitHelper.Commit("提交信息");
if (commitResult.Success)
{
    Console.WriteLine("提交成功");
}

远程操作

// 获取所有远程仓库
var remotes = gitHelper.GetAllRemotes();
foreach (var remote in remotes)
{
    Console.WriteLine($"远程仓库: {remote}");
}

推送和拉取

项目还提供了专门的 GitPushHelper、GitPullHelper、GitFetchHelper 和 GitMergeHelper 类来处理特定的 Git 操作。

// 推送到远程仓库
var pushHelper = new GitPushHelper(gitHelper);
var pushResult = pushHelper.Push("origin", "main");

API 参考

GitProcessHelper 类

主要的 Git 操作类,提供以下方法:

  • Clone() - 克隆仓库
  • Status() - 查看状态
  • Log() - 查看日志
  • Commit() - 提交更改
  • Add() - 添加文件到暂存区
  • Branch() - 分支操作
  • GetLocalBranch() - 获取本地分支
  • GetRemoteBranch() - 获取远程分支
  • GetCurrentBranch() - 获取当前分支
  • Remote() - 远程仓库操作
  • GetAllRemotes() - 获取所有远程仓库
  • Checkout() - 切换分支或恢复文件

GitResult 类

表示 Git 命令执行结果:

  • Command - 执行的命令
  • Output - 命令输出结果
  • Error - 错误信息
  • ExitCode - 退出代码
  • Success - 是否执行成功

许可证

本项目采用 MIT 许可证,详见 LICENSE 文件。

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net5.0-windows7.0 is compatible.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net6.0-windows7.0 is compatible.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net7.0-windows7.0 is compatible.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net9.0-windows7.0 is compatible.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETFramework 4.8.1

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net5.0-windows7.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net6.0-windows7.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net7.0-windows7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.
  • net9.0

    • No dependencies.
  • net9.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2025.827 248 8/27/2025

更新说明:Git帮助类