Skip to content
pb-diff Help

Your first three-way merge

The scenario: you and a colleague both started from the same n_pricing.sru and both changed it. Your version is in mine, theirs is in theirs, and the version you both started from is in base. A three-way merge compares each version with the Base, so it can tell your change from theirs, and carries both into one merged object. The files are in the three-way folder of the Order Desk examples; see Your first comparison.

n_pricing computes the discount and the shipping cost of an order. From the same Base, File1 raised the discount for orders of 500 or more from 5% to 6%; File2 raised it to 7%, and also made shipping free from 250 instead of 300 and cheaper below that.

Open the merge

Choose Compare ▸ New Comparison and select Three-way merge. Give it three-way/mine/n_pricing.sru as File1, three-way/base/n_pricing.sru as Base and three-way/theirs/n_pricing.sru as File2: type them, browse for them, or drop all three onto the dialog. A drop fills them in the order Windows hands them over, so check that the Base is in the middle; the button with the two arrows between two rows swaps them. Choose Compare.

Read the tab

One hierarchy tree serves all three files, and it carries two columns of markers: the left rail is what File1 changed relative to the Base, the right rail is what File2 changed. A node with a marker in both rails is one that both of you touched, and that is where a conflict may be. Beside the tree, File1, the Base and File2 are shown side by side, lined up on the Base. Below them is the merged result, the one that will be saved, and under it the Merge Actions list: every change that has to be carried into the Base, with what it still needs, To apply or Conflict.

Run Auto Merge

Choose Auto Merge in the tool bar, or Compare ▸ Merge ▸ Auto Merge. It applies every change only one side made and leaves the conflicts alone. The shipping change was made on one side only, so it is merged. The discount was changed on both, so it stays a conflict: of_discount is marked in both rails, the three panes highlight the line, and the Merge Actions list still shows it open.

pb-diff three-way merge of n_pricing after Auto Merge. The function of_discount is selected and marked in both change rails of the shared tree. File1, the Base and File2 are shown side by side, lined up on the Base, with the conflicting line marked across all three: one side set the rate to 0.06 and the other to 0.07; the merged result below is highlighted as a conflict; and the Merge Actions list, whose rows each carry Take from Left, Keep Base and Take from Right buttons, shows of_discount as a conflict and of_shipping resolved automatically from File2.
Both sides changed the discount rate for orders of 500 or more in n_pricing. One tree serves the three files; its two rails show which side changed what, and the Merge Actions list shows the conflict still open after Auto Merge. Select the image to view it at full size.

Resolve the conflict

To accept File2's function, choose the Right button on the of_discount row of the Merge Actions list, which is Take from Right for that row's whole item. This deliberately discards File1's 6%; it is your decision, not an automatic choice. When neither side is right, type the answer into the merged pane instead: that is usually what a real conflict needs. Both rows now read Resolved, and the line above the list says that only saving is left.

pb-diff three-way merge of n_pricing after the conflict in of_discount was resolved by taking File2's version: the merged result shows the 0.07 rate highlighted, both rows of the Merge Actions list read Resolved, a banner above the list says all actions are resolved and the result can be saved, and the tool bar carries a Save button.
The conflict was resolved with the Take from Right button on its row. Every action is resolved, the list says only saving is left, and the merged file has been saved. Select the image to view it at full size.

Save

Choose Save. The dialog opens in the Base's folder and proposes the Base's name with .merged before the extension, n_pricing.merged.sru, so the Base stays as it is unless you choose its name. Pick a folder of your own: the examples installed under Program Files cannot be written to. The saved file is a PowerBuilder export, ready to import or check in. pb-diff never writes conflict markers such as <<<<<<< into it; if you save while conflicts remain, it asks whether to save a partial result.

After the decision, the saved result is File2's version, since File2 changed everything File1 did. This check returns exit code 0 (result):

pb-diff-cli compare three-way/theirs/n_pricing.sru three-way/merged/n_pricing.sru --format json

The CLI performs the merge too. With a conflict left it reports it with exit code 3 and writes nothing (result):

pb-diff-cli merge3 three-way/mine/n_pricing.sru three-way/base/n_pricing.sru three-way/theirs/n_pricing.sru --format json

As with every merged export, import it into a scratch PowerBuilder target and build it before relying on it.

Next