LibGit2Sharp how to resolve a conflict?

非 Y 不嫁゛ 提交于 2019-12-04 03:33:15

问题


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
        } 
    }
}

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.

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

Thank you for any help!


回答1:


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.

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

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").



来源:https://stackoverflow.com/questions/33812895/libgit2sharp-how-to-resolve-a-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!