我使用Libgit2sharp,我想解决冲突。在类“冲突”中,我有3个IndexEntry属性(祖先,我们的,他们的),每个属性都有指向同一个文件的属性"Path“。
我想使用TortoiseGitMerge工具,我想生成基本/我们/他们/他们的文件.
我怎么能这么做?
提前感谢!
发布于 2015-10-07 11:48:33
您可以从ConflictCollection中获得Index
var conflicts = repository.Index.Conflicts;然后获取特定文件的冲突:
var conflict = conflicts["Foo.cs"];然后,您可以得到冲突的每一方的IndexEntry:
var ancestor = conflict.Ancestor;
var ours = conflict.Ours;
var theirs = conflict.Theirs;通过索引条目,您可以获得以下对象:
var ancestorBlob = (ancestor != null) ? repository.Lookup(ancestor.Id) : null;
var ourBlob = (ours != null) ? repository.Lookup(ours.Id) : null;
var theirBlob = (theirs != null) ? repository.Lookup(theirs.Id) : null;你可以得到每一边内容的流:
var ancestorStream = (ancestor != null) ? ancestorBlob.GetContentStream(new FilteringOptions(ancestor.Name));
var ourStream = (ours != null) ? ourBlob.GetContentStream(new FilteringOptions(ours.Name));
var theirStream = (theirs != null) ? theirBlob.GetContentStream(new FilteringOptions(theirs.Name));然后您可以编写每个文件--记住,如果文件在每一边重命名,冲突可能有三种不同的路径,并且您应该检查每个Conflict.Name。例如,将其中一方写入磁盘:
using (var ancestorOutputStream = File.Create(ancestor.Name + ".orig"))
{
ancestorStream.CopyTo(ancestorOutputStream);
}https://stackoverflow.com/questions/32988249
复制相似问题