我有这样的方法,我从上一次提交中获得文件:
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
}
}
}
发布于 2015-05-13 05:17:15
由于git如何在文件系统中存储数据,所以git提交是提交中包含的所有文件的快照。然后,Tree
对象返回存储库中所有文件的状态。
我认为您必须在此提交树与前一个提交树之间进行区分,我认为应该使用Repository.Diff.Compare()
方法来完成。
https://stackoverflow.com/questions/30214314
复制相似问题