Text diff and merge
Compare two texts line by line, apply a unified diff and merge three versions, like diff, patch and git merge-file. Typical uses: show the changes between two versions of a script or a document, merge concurrent edits.
text difftext difftext patchtext patchtext merge3text merge3

text diff <text_a> <text_b>


Description

    Compare two texts line by line: JSON {mode, identical, added, removed, minimal, unified (the unified diff with 3 lines of context, labels a and b), hunks: [{header, old_start, old_lines, new_start, new_lines, changes: [{op: context | delete | insert, old_line, new_line, text, no_newline_at_end when true}]}]}

Parameters

    text_a:   The old text - String - required
    text_b:   The new text - String - required
admin
text diff "Le client paie par carte. La facture part le lundi. Relance au bout de 30 jours. " "Le client paie par carte ou virement. La facture part le lundi. Relance au bout de 15 jours. Copie au comptable. "
mentdb
{"mode": "lines", "identical": false, "added": 3, "removed": 2, "minimal": true, "unified": "--- a\ +++ b\ @@ -1,3 +1,4 @@\ -Le client paie par carte.\ +Le client paie par carte ou virement.\ La facture part le lundi.\ -Relance au bout de 30 jours.\ +Relance au bout de 15 jours.\ +Copie au comptable.\ ", "hunks": [{"header": "@@ -1,3 +1,4 @@", "old_start": 1, "old_lines": 3, "new_start": 1, "new_lines": 4, "changes": [{"op": "delete", "old_line": 1, "new_line": null, "text": "Le client paie par carte."}, {"op": "insert", "old_line": null, "new_line": 1, "text": "Le client paie par carte ou virement."}, {"op": "context", "old_line": 2, "new_line": 2, "text": "La facture part le lundi."}, {"op": "delete", "old_line": 3, "new_line": null, "text": "Relance au bout de 30 jours."}, {"op": "insert", "old_line": null, "new_line": 3, "text": "Relance au bout de 15 jours."}, {"op": "insert", "old_line": null, "new_line": 4, "text": "Copie au comptable."}]}]}

text diff <text_a> <text_b> <json_params>


Description

    Compare two texts with parameters: mode (lines, words, chars), format (json, unified: only the unified diff, html: and ), context (3: the lines around each change), from_label and to_label (a and b), ignore_case (false), ignore_whitespace (none, trailing, all), literal_breaks (true)

Parameters

    text_a:   The old text - String - required
    text_b:   The new text - String - required
    json_params:   The parameters, as a JSON object - String - required
admin
text diff "Le client paie par carte. La facture part le lundi. Relance au bout de 30 jours. " "Le client paie par carte ou virement. La facture part le lundi. Relance au bout de 15 jours. Copie au comptable. " "{\"format\": \"unified\", \"context\": 1, \"from_label\": \"conditions_v1.txt\", \"to_label\": \"conditions_v2.txt\"}"
mentdb
--- conditions_v1.txt +++ conditions_v2.txt @@ -1,3 +1,4 @@ -Le client paie par carte. +Le client paie par carte ou virement. La facture part le lundi. -Relance au bout de 30 jours. +Relance au bout de 15 jours. +Copie au comptable.
Word by word
admin
text diff "Livraison sous 5 jours ouvrés" "Livraison sous 3 jours ouvrés, gratuite" "{\"mode\": \"words\"}"
mentdb
{"mode": "words", "identical": false, "added": 4, "removed": 1, "minimal": true, "changes": [{"op": "equal", "text": "Livraison sous "}, {"op": "delete", "text": "5"}, {"op": "insert", "text": "3"}, {"op": "equal", "text": " jours ouvrés"}, {"op": "insert", "text": ", gratuite"}]}
Character by character, in HTML
admin
text diff "réf. AB-1024" "réf. AB-1042" "{\"mode\": \"chars\", \"format\": \"html\"}"
mentdb
réf. AB-10<del>2</del>4<ins>2</ins>
Case and spaces ignored
admin
text diff "Total : 100 " "TOTAL : 100 " "{\"ignore_case\": true, \"ignore_whitespace\": \"all\"}"
mentdb
{"mode": "lines", "identical": true, "added": 0, "removed": 0, "minimal": true, "unified": "", "hunks": []}
Used in use cases (1 recipe)

    Integrator & ETL developer › Review a configuration change as a diff, apply it elsewhere and merge two edits
Often used with

    text merge3  ·  text patch

text patch <text> <unified_diff>


Description

    Apply a unified diff to a text: the new text. An error, and nothing changed, when a hunk does not apply

Parameters

    text:   The text to change - String - required
    unified_diff:   The unified diff (one file) - String - required
admin
text patch "Le client paie par carte. La facture part le lundi. Relance au bout de 30 jours. " "--- a +++ b @@ -1,3 +1,4 @@ -Le client paie par carte. +Le client paie par carte ou virement. La facture part le lundi. -Relance au bout de 30 jours. +Relance au bout de 15 jours. +Copie au comptable. "
mentdb
Le client paie par carte ou virement. La facture part le lundi. Relance au bout de 15 jours. Copie au comptable.

text patch <text> <unified_diff> <json_params>


Description

    Apply a unified diff with parameters: fuzz (0, 3 at most: context lines that may differ at the start and the end of a hunk), reverse (false: true undoes the patch), max_offset (no limit: how far from its line number a hunk may be found), report (false: true gives {text, hunks: [{hunk, header, line, offset, fuzz}]}), ignore_whitespace (none, trailing, all), literal_breaks (true)

Parameters

    text:   The text to change - String - required
    unified_diff:   The unified diff - String - required
    json_params:   The parameters, as a JSON object - String - required
admin
text patch "Conditions Le client paie par carte. La facture part le lundi. Relance au bout de 30 jours. " "--- a +++ b @@ -1,3 +1,4 @@ -Le client paie par carte. +Le client paie par carte ou virement. La facture part le lundi. -Relance au bout de 30 jours. +Relance au bout de 15 jours. +Copie au comptable. " "{\"report\": true}"
mentdb
{"text": "Conditions\ \ Le client paie par carte ou virement.\ La facture part le lundi.\ Relance au bout de 15 jours.\ Copie au comptable.\ ", "hunks": [{"hunk": 1, "header": "@@ -1,3 +1,4 @@", "line": 3, "offset": 2, "fuzz": 0}]}
Undo the patch
admin
text patch "Le client paie par carte ou virement. La facture part le lundi. Relance au bout de 15 jours. Copie au comptable. " "--- a +++ b @@ -1,3 +1,4 @@ -Le client paie par carte. +Le client paie par carte ou virement. La facture part le lundi. -Relance au bout de 30 jours. +Relance au bout de 15 jours. +Copie au comptable. " "{\"reverse\": true}"
mentdb
Le client paie par carte. La facture part le lundi. Relance au bout de 30 jours.
A hunk that does not apply
admin
text patch "Le client paie par chèque. La facture part le lundi. Relance au bout de 30 jours. " "--- a +++ b @@ -1,3 +1,4 @@ -Le client paie par carte. +Le client paie par carte ou virement. La facture part le lundi. -Relance au bout de 30 jours. +Relance au bout de 15 jours. +Copie au comptable. "
mentdb
ERROR: Sorry, an error appears (hunk 1 (@@ -1,3 +1,4 @@) does not apply: at line 1 expected 'Le client paie par carte.', found 'Le client paie par chèque.').
Used in use cases (1 recipe)

    Integrator & ETL developer › Review a configuration change as a diff, apply it elsewhere and merge two edits
Often used with

    text diff  ·  text merge3

text merge3 <base> <ours> <theirs>


Description

    Merge two versions of a base text: JSON {clean, conflicts, auto_resolved, regions: [{line (of the marker <<<<<<< in text), ours_lines, theirs_lines}], text}

Parameters

    base:   The common base - String - required
    ours:   Our version - String - required
    theirs:   Their version - String - required
admin
text merge3 "titre: Devis montant: 100 delai: 30 jours " "titre: Devis client montant: 100 delai: 30 jours " "titre: Devis montant: 100 delai: 15 jours "
mentdb
{"clean": true, "conflicts": 0, "auto_resolved": 0, "regions": [], "text": "titre: Devis client\ montant: 100\ delai: 15 jours\ "}
The same line changed on both sides: a conflict
admin
text merge3 "titre: Devis montant: 100 delai: 30 jours " "titre: Devis client montant: 100 delai: 30 jours " "titre: Devis urgent montant: 100 delai: 30 jours "
mentdb
{"clean": false, "conflicts": 1, "auto_resolved": 0, "regions": [{"line": 1, "ours_lines": 1, "theirs_lines": 1}], "text": "<<<<<<< ours\ titre: Devis client\ =======\ titre: Devis urgent\ >>>>>>> theirs\ montant: 100\ delai: 30 jours\ "}

text merge3 <base> <ours> <theirs> <json_params>


Description

    Merge with parameters: style (merge or diff3: diff3 adds the base lines between ||||||| and =======, and keeps the conflicts as they are), favor (none, ours, theirs, union: resolve the conflicts), label_ours (ours), label_base (base), label_theirs (theirs), marker_size (7), literal_breaks (true)

Parameters

    base:   The common base - String - required
    ours:   Our version - String - required
    theirs:   Their version - String - required
    json_params:   The parameters, as a JSON object - String - required
admin
text merge3 "titre: Devis montant: 100 delai: 30 jours " "titre: Devis client montant: 100 delai: 30 jours " "titre: Devis urgent montant: 100 delai: 30 jours " "{\"style\": \"diff3\", \"label_ours\": \"commercial\", \"label_theirs\": \"direction\"}"
mentdb
{"clean": false, "conflicts": 1, "auto_resolved": 0, "regions": [{"line": 1, "ours_lines": 1, "base_lines": 1, "theirs_lines": 1}], "text": "<<<<<<< commercial\ titre: Devis client\ ||||||| base\ titre: Devis\ =======\ titre: Devis urgent\ >>>>>>> direction\ montant: 100\ delai: 30 jours\ "}
Their version wins the conflicts
admin
text merge3 "titre: Devis montant: 100 delai: 30 jours " "titre: Devis client montant: 100 delai: 30 jours " "titre: Devis urgent montant: 100 delai: 30 jours " "{\"favor\": \"theirs\"}"
mentdb
{"clean": true, "conflicts": 0, "auto_resolved": 1, "regions": [], "text": "titre: Devis urgent\ montant: 100\ delai: 30 jours\ "}
Used in use cases (1 recipe)

    Integrator & ETL developer › Review a configuration change as a diff, apply it elsewhere and merge two edits
Often used with

    text diff  ·  text patch