首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Libgit2sharp冲突获取他们/我们/基本文件的内容

Libgit2sharp冲突获取他们/我们/基本文件的内容
EN

Stack Overflow用户
提问于 2015-10-07 09:11:23
回答 1查看 807关注 0票数 1

我使用Libgit2sharp,我想解决冲突。在类“冲突”中,我有3个IndexEntry属性(祖先,我们的,他们的),每个属性都有指向同一个文件的属性"Path“。

我想使用TortoiseGitMerge工具,我想生成基本/我们/他们/他们的文件.

我怎么能这么做?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-07 11:48:33

您可以从ConflictCollection中获得Index

代码语言:javascript
复制
var conflicts = repository.Index.Conflicts;

然后获取特定文件的冲突:

代码语言:javascript
复制
var conflict = conflicts["Foo.cs"];

然后,您可以得到冲突的每一方的IndexEntry

代码语言:javascript
复制
var ancestor = conflict.Ancestor;
var ours = conflict.Ours;
var theirs = conflict.Theirs;

通过索引条目,您可以获得以下对象:

代码语言:javascript
复制
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;

你可以得到每一边内容的流:

代码语言:javascript
复制
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。例如,将其中一方写入磁盘:

代码语言:javascript
复制
using (var ancestorOutputStream = File.Create(ancestor.Name + ".orig"))
{
    ancestorStream.CopyTo(ancestorOutputStream);
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32988249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档