【发布时间】:2015-07-24 17:03:29
【问题描述】:
我有这个方法,我从上次提交中获取文件:
static void GetFiles(Tree t, String dir = "")
{
foreach (TreeEntry treeEntry in t)
{
if (treeEntry.TargetType == TreeEntryTargetType.Tree)
{
Tree tr = repo.Lookup<Tree>(treeEntry.Target.Sha);
GetFiles(tr, dir + "/" + treeEntry.Name);
}
else
{
string caminho = dir + "/" + treeEntry.Path;
arquivos.Add(caminho);
}
}
return;
}
我看过this question,但我是C#新手,不懂。
我有这个仓库:
c:/teste
| - octocat.txt
| - parentoctocat.txt
| - /outros
| | - octocatblue.txt
| | - octored.txt
我上次提交修改了这些文件:
c:/teste
| - /outros
| | - octocatblue.txt <- This modified
| | - octored.txt <- This new
使用我的方法GetFiles,我已经拥有了与此打印类似的所有文件。如何只获取修改/添加/删除的文件?
如何获取上一次提交并比较获取差异树?
解决方案
static void CompareTrees()
{
using (repo)
{
Tree commitTree = repo.Head.Tip.Tree; // Main Tree
Tree parentCommitTree = repo.Head.Tip.Parents.First().Tree; // Secondary Tree
var patch = repo.Diff.Compare<Patch>(parentCommitTree, commitTree); // Difference
foreach (var ptc in patch)
{
Console.WriteLine(ptc.Status +" -> "+ptc.Path); // Status -> File Path
}
}
}
【问题讨论】:
标签: c# git libgit2sharp