Recursive AI

Show base lines in a merge conflict in C#

OneDiff is a free, open-source diff library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Diff3 shows the shared original, or base, alongside both edits.

Terminal
dotnet add package RecursiveAI.OneDiff

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

Pass the unedited version first.

C#
using OneDiff;
using OneDiff.Merge;
Console.Write(Diff.Merge(
    baseText: "port=80\n",
    ours: "port=8080\n",
    theirs: "port=443\n",
    new() { Style = ConflictStyle.Diff3 }
).Text);

Unzip the example, then dotnet run.

Prints:

Text
<<<<<<< ours
port=8080
||||||| base
port=80
=======
port=443
>>>>>>> theirs

The original setting, port=80, appears after ||||||| base. If the edits merge cleanly, there are no conflict markers or base sections; keep the merge result and check its HasConflicts before saving the text as a finished merge.

Variations

Label the three versions. Replace the settings argument in the snippet with this one to make the branch names visible in the conflict:

C#
new MergeSettings
{
    Style = ConflictStyle.Diff3,
    OursLabel = "development",
    BaseLabel = "original",
    TheirsLabel = "release"
}

Move identical edge lines outside the conflict. Both styles print the base. Replace the settings argument with this one; it prints the same result for the single-line example.

C#
new MergeSettings { Style = ConflictStyle.ZDiff3 }

The short answer

Call Diff.Merge(baseText, ours, theirs, new MergeSettings { Style = ConflictStyle.Diff3 }) and display result.Text. The ||||||| base marker starts the original lines for that conflict; ======= ends the base section and starts the other side. The two sides and the base are all shown together, so a reviewer can compare each edit to what was there before.

How do you view the original lines in a merge conflict?

In the example, seeing only port=8080 and port=443 tells you the edits differ. Seeing port=80 as well tells you that neither side kept the original. The base section shows the original range for that conflict, not the entire original file. Keep the full base separately if the reviewer needs more context.

Read the sections in order: ours, base, then theirs. The labels describe the order in which your application submitted the inputs. If those files came from named branches, use the label settings to identify the actual branches instead of asking readers to remember which one is “ours.”

What is the difference between diff3 and zdiff3?

OneDiff’s conflict styles control how conflicts appear. The default Merge style shows just ours and theirs. Diff3 shows the base as a third section without narrowing the conflict. ZDiff3 also shows the base, but moves lines that both sides share at the start or end of a conflict outside the markers; the base section itself stays whole.

Use Diff3 when you want the full conflicting ranges visible together. Use ZDiff3 when repeating the same opening or closing lines makes the edits harder to spot. Neither style selects a winning edit. HasConflicts still tells you whether the result needs review, and the marker lines are for the reviewer, not for the application that consumes the final settings file.

All onediff recipes