我已经创建了一个存储库,并使用octokit.net和创建了一个使用“完全提交”方法的新提交。我已经成功地在本教程之后创建了一个“一个文件/一行”提交。但是“完全提交”部分不起作用。我在使用Octokit版0.24.1-alpha0001.
<PackageReference Include="Octokit" Version="0.24.1-alpha0001"/>我的密码在这里:
var Client = new GitHubClient(new ProductHeaderValue("my-cool-app"));
var Owner = "Owner";
var RepositoryName = "RepositoryName";
var Password = "Password";
Client.Credentials = new Credentials(Owner, Password);之后,我用这个创建了一个存储库。
var context = Client.Repository.Create(repository);以下是我的“完全提交”部分:
using Octokit;
try {
// 1. Get the SHA of the latest commit of the master branch.
var headMasterRef = "heads/master";
var masterReference = Client.Git.Reference.Get(Owner, RepositoryName, headMasterRef).Result; // Get reference of master branch
var latestCommit = Client.Git.Commit.Get(Owner, RepositoryName,
masterReference.Object.Sha).Result; // Get the laster commit of this branch
var nt = new NewTree { BaseTree = latestCommit.Tree.Sha };
//2. Create the blob(s) corresponding to your file(s)
var textBlob = new NewBlob { Encoding = EncodingType.Utf8, Content = "Hellow World!" };
var textBlobRef = Client.Git.Blob.Create(Owner, RepositoryName, textBlob);
// 3. Create a new tree with:
nt.Tree.Add(new NewTreeItem { Path = fileRel.RelativePath, Mode = "100644", Type = TreeType.Blob, Sha = textBlobRef.Result.Sha });
var newTree = Client.Git.Tree.Create(Owner, RepositoryName, nt).Result;
// 4. Create the commit with the SHAs of the tree and the reference of master branch
// Create Commit
var newCommit = new NewCommit("Commit test with several files", newTree.Sha, masterReference.Object.Sha);
var commit = Client.Git.Commit.Create(Owner, RepositoryName, newCommit).Result;
// 5. Update the reference of master branch with the SHA of the commit
// Update HEAD with the commit
Client.Git.Reference.Update(Owner, RepositoryName, headMasterRef, new ReferenceUpdate(commit.Sha));
} catch (AggregateException e) {
Console.WriteLine($"An exception is detected in the commit step. {e.Message}");
}没有例外,所有的事情似乎都已经定义好了,但是当我转到存储库的主分支时,就没有提交了。只有最初的提交。
发布于 2017-08-12 18:14:36
我终于发现了问题。我错过了.Result在Client.Git.Reference.Update线。这个很好用。谢谢Jérémie Bertrand。
我更新了
// 5. Update the reference of master branch with the SHA of the commit
// Update HEAD with the commit
Client.Git.Reference.Update(Owner, RepositoryName, headMasterRef, new
ReferenceUpdate(commit.Sha));到此代码
Client.Git.Reference.Update(Owner, RepositoryName, headMasterRef, new
ReferenceUpdate(commit.Sha)).Result;我在git对象(newTree,commit)上发现了一个断点: urls就在这里。本教程是正确的,因为它使用了等待:
await github.Git.Reference.Update(owner, repo, headMasterRef, new ReferenceUpdate(commit.Sha));https://stackoverflow.com/questions/45263772
复制相似问题