我试图通过挖掘一个混帐存储库,以获取有关提交历史的一些信息。我正在使用包libgit2sharp。如何获取单个提交的每个更改文件的修补程序?
到目前为止,我提交的作者,提交者,SHA-值,提交时间和提交消息。我的问题是移动存储库树,以获取每个提交的所有更改文件的修补程序。
有谁之前解决这个问题,或者它可以帮助我吗?
using (var repo = new Repository(@"path\to\.git"))
{
var commits = repo.Commits;
Commit lastCommit = commits.Last();
foreach (Commit commit in commits)
if (commit.Sha != lastCommit.Sha)
{
Console.WriteLine(commit.Sha);
Console.WriteLine(commit.Author.Name);
Console.WriteLine(commit.Committer.Name);
Console.WriteLine(commit.Author.When); //Commit-Date
Console.WriteLine(commit.Message);
Tree tree = commit.Tree;
Tree parentCommitTree = lastCommit.Tree;
TreeChanges changes = repo.Diff.Compare<TreeChanges>(parentCommitTree, tree);
foreach (TreeEntryChanges treeEntryChanges in changes)
{
ObjectId oldcontenthash = treeEntryChanges.OldOid;
ObjectId newcontenthash = treeEntryChanges.Oid;
}
}
}
另一个问题是下面的代码。它显示了根级别的文件和文件夹,但我无法打开文件夹。
foreach(TreeEntry treeEntry in tree)
{
// Blob blob1 = (Blob)treeEntry.Target;
var targettype = treeEntry.TargetType;
if (targettype == TreeEntryTargetType.Blob)
{
string filename = treeEntry.Name;
string path = treeEntry.Path;
string sha = treeEntry.Target.Sha;
var filemode = treeEntry.Mode;
Console.WriteLine(filename);
Console.WriteLine(path);
}
else if (targettype == TreeEntryTargetType.Tree)
{
Console.WriteLine("Folder: " + treeEntry.Name);
}
}
例外是不应该发生的。您能否向** [问题跟踪器](https://github.com/libgit2/libgit2sharp/issues/new)**提交完整的repro案件? – nulltoken
这是完整的代码。它发生在ca. 7.000提交 – Thomas
请在跟踪器中提交一个专用问题以及您正在使用的公共存储库的URL – nulltoken