问题描述
我正在尝试使用 LibGit2Sharp 将单个特定提交推送到远程分支。
我正在寻找相当于 {
"id": 3,"balancetoItem": []
}
https://miteshshah.github.io/linux/git/how-to-push-single-commit-with-git/
LibGit2Sharp 有没有类似的东西?或者有更好的方法吗?
谢谢,
加里克
解决方法
你看过their documentation吗?据此,您应该可以使用:
using (var repo = new Repository("path/to/your/repo"))
{
LibGit2Sharp.PushOptions options = new LibGit2Sharp.PushOptions();
options.CredentialsProvider = new CredentialsHandler(
(url,usernameFromUrl,types) =>
new UsernamePasswordCredentials()
{
Username = USERNAME,Password = PASSWORD
});
repo.Network.Push(repo.Branches[BRANCHNAME],options);
}
另一种变体,使用 Remote 推送到原点:
using (var repo = new Repository("path/to/your/repo"))
{
Remote remote = repo.Network.Remotes["origin"];
var options = new PushOptions();
options.CredentialsProvider = (_url,_user,_cred) =>
new UsernamePasswordCredentials { Username = "USERNAME",Password = "PASSWORD" };
repo.Network.Push(remote,@"refs/heads/master",options);
}