LibGit2Sharp如何解决冲突? [英] LibGit2Sharp how to resolve a conflict?

查看:272
本文介绍了LibGit2Sharp如何解决冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用libgit2sharp我从两个用户更改合并:

Using libgit2sharp I am merging changes from two users:

public void Merge(string branchName)
{
    using (Repository repo = new Repository(this._settings.Directory))
    {
        var branch = repo.Branches[branchName];
        MergeOptions opts = new MergeOptions() { FileConflictStrategy = CheckoutFileConflictStrategy.Merge };
        repo.Merge(branch, this._signature, opts);

        if (repo.Index.Conflicts.Count() > 0)
        {
             //TODO: resolve conflicts
        } 
    }
}

即使策略设置为合并conflics仍然会出现。我发现没有办法来解决冲突。冲突对象有没有解决的方法。

Even if the strategy is set to merge the conflics still appear. I found no way to resolve the conflict. The Conflict object have no Resolve method.

有没有办法来解决从code除了有冲突的文件,删除或重命名呢?是否有任何自动解决功能?

Is there a way to resolve a conflict from code apart from removing file or renaming it? Is there any auto resolve functionality?

感谢您的帮助!

推荐答案

LibGit2Sharp的确实的做一个automerge。如果看到冲突,那么这些文件是不可合并。一个不可合并冲突的一个例子是,当两个分支改变同一文件的相同区域。

LibGit2Sharp does do an automerge. If you are seeing conflicts, then the files are unmergeable. An example of an unmergeable conflict is when both branches change the same region of the same file.

在这种情况下,LibGit2Sharp将文件写入到工作目录,与各地的冲突地区的标记。例如,如果某些文件 foo.txt的有冲突,它可能看起来像:

In this case, LibGit2Sharp will write the file to the working directory, with markup around the conflicting region. For example, if some file foo.txt has a conflict, it may look like:

<<<<<<< HEAD
this is a change in HEAD
=======
this is a change in the other branch
>>>>>>> other branch

要解决冲突,将要接受在工作目录的内容,然后使用阶段, Repository.Index.Add(上面的foo.txt)

To resolve the conflict, place the content that you want to accept in the working directory, then stage it using Repository.Index.Add("foo.txt").

这篇关于LibGit2Sharp如何解决冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆