//ok
private static void push()
{
string wkDir = @"E:\DotNet2010\单位工程\Git.Client\lib2Test\ConsoleApplication1\bin\Debug\D2Git\.git";
using (var repo = new Repository(wkDir))
{
//此时必须保证存在 one.txt,two.txt 两个文件
string fname = "one.txt";
repo.Index.Stage(fname);
repo.Commit("add one", Constants.Signature, Constants.Signature);
fname = "two.txt";
repo.Index.Stage(fname);
repo.Commit("add two", Constants.Signature, Constants.Signature);
var nk = repo.Network;
PushOptions po = new PushOptions
{
CredentialsProvider = (x, y, z) => new UsernamePasswordCredentials { Username = "admin", Password = "admin" }
};
nk.Push(repo.Head, po);
nk.Push(repo.Branches["master"], po);
}
}
public static class Constants
{
public static readonly Signature Signature = new Signature("javasuki", "javasuki@hotmail.com", new DateTimeOffset(2014, 06, 22, 10, 58, 27, TimeSpan.FromHours(2)));
}

本文介绍如何使用LibGit2Sharp库在C#中实现Git的基本操作,包括将指定文件加入暂存区并提交,最后将更改推送到远程仓库的过程。文中提供了一个具体的示例,展示了如何通过代码实现这些功能。
1303

被折叠的 条评论
为什么被折叠?



