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.
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.
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
- Three-way merge: the tab, the Merge Actions list and every merge command.
- How merging works: what a merge writes, and the four places a control lives.
- Source-control clients: pb-diff as the merge tool of TortoiseGit, TortoiseSVN or Git.