libra merge

Command reference for `libra merge`

Merge one or more targets into the current branch.

Synopsis

libra merge [--ff] [--ff-only] [--no-ff] [-s <strategy>...] [-X <option>...] [--allow-unrelated-histories] [--log[=<n>] | --no-log] [--squash | --no-commit] [-m <msg> | -F <file>] [--into-name <name>] [-e | --edit | --no-edit] [--cleanup=<mode>] [--no-verify] [-v | --verbose] [--stat | -n | --no-stat] [--verify-signatures | --no-verify-signatures] [--rerere-autoupdate | --no-rerere-autoupdate] [-S | --gpg-sign | --no-gpg-sign] [--signoff] [--dry-run] [--autostash | --no-autostash] <branch>...
libra merge --continue [-m <msg> | -F <file>] [-e | --edit | --no-edit] [--cleanup=<mode>] [--no-verify] [-S | --gpg-sign | --no-gpg-sign] [--signoff]
libra merge --abort
libra merge --quit
libra merge --restart

Description

An unreadable attribute source or unsafe worktree path stops the preflight with LBR-IO-001 and retains the underlying cause so it can be corrected before retrying.

The clean-worktree preflight compares tracked regular files using explicit text/eol rules. CRLF bytes that clean to the indexed LF content do not block merge --ff-only. Real edits, mode/type changes and existing conflict or merge state retain their normal protection. text=auto uses the same comparison with binary detection and protection for historical CRLF index content. See add for --renormalize, bounded index evidence reads and remaining configuration limits.

libra merge <branch>... resolves one or more local branches, commit hashes, or remote-tracking refs such as refs/remotes/origin/main. One target keeps the single-head behavior described below; two or more targets select an octopus merge.

Before starting a merge, Libra checks both merge state and the index. Existing merge state still directs you to merge --continue, --abort, or --quit. After conflicts are staged, a regular libra commit also finishes the merge (two parents, saved merge message, then clear merge state and apply a held autostash). --quit clears only merge bookkeeping: it leaves HEAD, index stages, and conflict-marked files untouched; a held autostash is moved into the visible stash list rather than re-applied. With no merge in progress, --quit returns LBR-REPO-003 (exit 128) and tells you to start a merge; this is intentionally different from Git's silent no-op. If there is no merge state but unresolved index entries remain (for example after a conflicted squash), even an already-up-to-date merge or --dry-run fails with LBR-CONFLICT-002 (exit 128), preserving HEAD, the index and working tree. Resolve the conflicts, stage the paths with libra add, and run a plain libra commit before starting another merge.

During a non-squash merge stopped on conflicts, Libra records an AUTO_MERGE tree containing the automatic result, including conflict markers. It is a projected pseudo-ref, not a stored loose ref: libra rev-parse AUTO_MERGE, libra cat-file, and libra diff can consume it only while that merge state exists. merge --continue, --abort, and --quit remove the state and therefore make it unavailable; clean and squash merges do not create it. Other pseudo-refs, including all write paths such as update-ref, remain rejected.

If the current branch can be fast-forwarded, Libra moves the branch pointer to the target commit and restores the index and working tree. If the branches have diverged, Libra performs a single-head three-way merge using the merge base — or, when the history leaves more than one merge base, using a recursive virtual ancestor built from all of them (see below).

The default single-head strategy is ort. The default for two or more targets remains the automatic octopus path. The selected backend is named in human success output and, for JSON consumers, in the additive selected_strategy field; the historical strategy field remains an outcome category such as three-way, ours, or octopus.

Strategy selection

-s / --strategy accepts these built-in names:

Strategy Behavior
ort The default single-head three-way backend: all merge bases are recursively folded when needed, and rename detection is enabled.
recursive A compatibility alias for ort; behavior is identical, while output records the requested name.
resolve A conservative single-head three-way backend: it takes the first object-id-ordered merge base, never builds a recursive virtual ancestor, and disables rename handling. A rename therefore degrades deterministically to delete/add (and can leave a modify/delete conflict); human output prints a notice naming the old and new paths.
ours Records HEAD and every surviving target as parents while retaining the complete current HEAD tree. This is distinct from -X ours.

For a single target, -s is repeatable. Libra probes the names in command-line order without repository writes, prints Trying merge strategy <name>... in human mode, and executes the first clean result. If every strategy conflicts, it replays the best result using Git's evaluate_result score (worktree/index differences plus unmerged index entries); the later strategy wins a tie. The selected backend is persisted in non-squash merge state, so --continue reports it and --restart reproduces it instead of silently returning to the default.

With several targets, omit -s for automatic octopus, or use one -s ours. The explicit name -s octopus, single-head strategies on several targets, external git-merge-<name> programs, and subtree are not implemented. An unknown or incompatible name fails before mutation with an actionable error. -s cannot be combined with -X.

The ort/recursive three-way backend accepts conflict-side, whitespace-comparison, and renormalization -X options. -X ours / -X theirs choose a side only for conflicting hunks/paths while retaining clean changes from both sides. See “Input normalization” below for the other supported values.

Octopus merges (several targets)

With two or more targets, Libra reduces duplicate targets and targets reachable from another supplied target, retaining the command-line order of the independent tips. If every surviving target is already reachable from HEAD, the result is Already up to date. Otherwise the octopus path never fast-forwards: a successful merge commit has HEAD first, followed by the surviving targets in command-line order. --ff-only therefore refuses a non-up-to-date octopus merge.

Before the strategy starts, Libra requires one common history across HEAD and every target unless --allow-unrelated-histories is present, matching Git's all-tip octopus entry gate. The trees are then merged one target at a time in memory. Each round computes the common ancestors between that target and a hypothetical merge of the merge-reference commits already incorporated, including every criss-cross LCA; this is intentionally not the all-tip intersection. Libra writes no merge object, index entry, tracked working-tree path, merge state, ref, or reflog until every round is clean. If any round conflicts, the command fails with LBR-CONFLICT-002, names the target and paths, includes “Should not be doing an octopus”, and leaves HEAD, index, and working tree unchanged. No conflict state is created; merge the targets one at a time if conflicts need resolution.

Clean octopus merges support --no-commit: the state records every target as a GC root, --continue creates the same ordered multi-parent commit, and --abort restores the pre-merge state. --squash, --dry-run, --autostash, -s ours, -X options, unrelated-history permission, merge-message shortlogs, hooks, and signature verification also apply; --verify-signatures verifies every resolved target before mutation. An octopus dry-run reports a clean octopus result or a read-only would-conflict result. As with single-head external merge drivers, a trusted unsandboxed driver can directly mutate the repository outside Libra's atomic rollback boundary.

Criss-cross histories (several merge bases)

Two branches that have already merged each other leave several merge bases, none of them better than the others. Picking one arbitrarily reports conflicts that the history actually explains, so Libra folds them the way Git's recursive strategy does:

  1. The merge bases are sorted by object id and folded pairwise, left to right, each fold being itself a three-way merge (with its own merge base, recursively).
  2. The single tree that comes out — the virtual ancestor — is the base of the real merge.

Inside the fold, decisions differ from a real merge, matching Git:

  • -X ours / -X theirs do not apply; a virtual ancestor is a synthetic input, not something you asked to bias.
  • A content conflict is not surfaced. It is recorded as content, with the conflict markers widened by two characters per recursion level so a nested conflict can never be read as one the outer merge produced.
  • A change/delete keeps the base version: there is no midpoint between "changed" and "gone".
  • Binary content (Git's rule: a NUL byte in the first 8000, or an input larger than 1023 MiB) is not line-merged; the ancestor keeps the base's content, or the empty blob when there is no base.
  • Symlinks — and any two sides that are different kinds of entry — keep the base version, which means the path is simply absent from the ancestor when there is no base.
  • The resulting file mode follows Git's rule: the other side's mode when the two agree or ours is unchanged, otherwise ours.
  • Nesting deeper than 20 levels, or more than 32 merge bases at one level — counted on the bare ids before any base is loaded, and again on the candidate ancestors collected while folding — is refused with LBR-UNSUPPORTED-001 rather than recursed (the fold's work grows with the square of the width; a criss-cross has two). -s resolve, -s ours, and --ff-only never fold and are never refused for width (resolve selects one deterministic real base; a diverged --ff-only merge is refused as non-fast-forward, as always).

The synthetic commit's parents are all the real merge bases folded so far (Git chains one two-parent virtual commit per fold step); the reachable history is the same, the object ids are not. The virtual ancestor's tree and its synthetic commit are written as ordinary loose objects, but they are one-shot: they are deliberately not recorded in the merge state, so they are not garbage-collection roots. libra maintenance run --task gc may reclaim them at any time, including while a conflicted merge is still in progress — nothing depends on them surviving, and libra merge --restart recomputes the same ancestor from the real merge bases. Consequently merge-state.json records a base only when the merge base is a single real commit.

libra merge --dry-run previews a criss-cross merge under the same contract as any other preview — no object-store, index, working-tree, HEAD, reflog, merge-state or autostash-sidecar write: the fold keeps its blobs in memory and materializes no virtual tree or commit. (What the contract does not cover is repository-wide housekeeping the CLI performs before any command runs, such as the schema auto-upgrade on database open; see docs/development/commands/merge.md.)

Histories without a common ancestor remain rejected unless --allow-unrelated-histories is explicit. With it, Libra uses a virtual empty merge base: disjoint root trees combine normally, overlapping additions conflict normally, and non-squash conflict state survives --continue, --abort, and --restart without creating a fake base object.

By default, clean three-way merges create a two-parent merge commit, update HEAD, rebuild the index, restore the working tree, and write a merge reflog entry. Conflicting three-way merges write line-level conflict markers to the working tree (matching Git — only the diverging hunks are enclosed between <<<<<<< HEAD / ======= / >>>>>>> <user-spelling>; the >>>>>>> label is the merge target exactly as typed — side, refs/heads/side, or a hash prefix — and --restart rereads that spelling from merge-state.json; the renderer re-diffs both postimages so common edges and sufficiently long common runs stay outside; binary or modify/delete paths fall back to whole-file markers), write unmerged index stages, save Libra merge state unless --squash was requested, and return LBR-CONFLICT-002. Non-squash conflicts provide hints for libra merge --continue and libra merge --abort; squash conflicts instead direct you to resolve and stage the paths, then run a plain libra commit to create a single-parent commit. A squash leaves HEAD unchanged and records no merge state, even when it conflicts, so merge --continue, --abort, and --restart report no merge in progress.

Conflict style (merge.conflictStyle)

The marker format follows the Git-compatible merge.conflictStyle config key (config-only — matching Git, merge has no CLI style flag):

libra config merge.conflictStyle diff3
  • merge (default, or unset) — the two-marker style above. Conflicting postimages are re-diffed: equal prefixes and suffixes are moved outside the markers, equal runs longer than three lines split neighboring conflict blocks, and runs of up to three lines remain inside one block to avoid noisy fragmentation.
  • diff3 — additionally emits the common-ancestor content between a ||||||| <merge-base-abbrev7> marker and the ======= separator, so you can see what both sides started from. Several merge bases keep the historical base ancestor label.
  • zdiff3 — emits the same complete ancestor block as diff3, while moving equal prefixes and suffixes of the two postimages outside the markers. It deliberately does not apply merge style's internal equal-run splitting.
  • Any other value is a hard error when a content merge must be rendered (exit 128), never a silent fall-back to the default style.

For a merge with several merge bases the value is read before the merge runs rather than only when a conflict is rendered, because the recursive virtual ancestor's own content depends on it (Git does the same at every recursion depth). An invalid value therefore stops a criss-cross merge even when that merge would have come out clean.

The config is honored by libra merge, libra cherry-pick, and libra revert for text conflicts. NUL-containing content handled by the text fallback and modify/delete conflicts keep their two-part whole-file presentation (Git also emits no base block there); an explicitly selected binary driver instead keeps ours without markers. Marker lines use CRLF when every detected input line ending is CRLF; otherwise they use LF. Refinement changes presentation only: a genuine conflict remains a conflict, except that byte-identical postimages become a clean result. libra rebase currently renders whole-file markers without a base block regardless of this setting.

Per-path merge drivers (gitattributes)

For a path whose contents changed on both sides, Libra reads the existing .gitattributes / .libra_attributes cascade and dispatches the merge attribute like Git's low-level merge layer:

  • Bare merge uses the normal line-level text merge; -merge treats the file as indivisible. An unresolved binary conflict keeps the complete ours version in the working tree, writes stages 1/2/3 to the index, and emits no markers.
  • A named value first selects a matching external configuration. Without one, merge=text and merge=binary select those built-ins, while merge=union resolves each overlapping region by retaining ours followed by theirs. If xdiff classifies any union input as binary (for example, a NUL byte), union falls back to a whole-file binary conflict and keeps ours without markers.
  • A named value with no configured external or known built-in falls back to text; it is not an error and does not consult merge.default.

When a path has no merge attribute, merge.default=<name> selects the fallback driver. An unset or unknown name falls back to text, unless the name has an external command configured as merge.<name>.driver. External commands are read once through the strict local → global → system config cascade. A configured command wins over a same-named built-in (merge=text can therefore be overridden); the boolean attributes merge and -merge always select the built-in text and binary drivers directly.

libra merge runs the configured value through sh -c, preserving the POSIX single-quote semantics used by Git (Windows therefore also needs a compatible sh on PATH). This is a trusted-config boundary: the command is not sandboxed or timed out, so do not import merge.*.driver values from an untrusted source. Its placeholders are:

  • %O, %A, %B: absolute paths to unpredictable temporary base, ours, and theirs files; shell-safe paths retain Git's unquoted expansion, while paths inherited from an unsafe worktree name are single-quoted to prevent that directory name from becoming shell syntax. Native path bytes are preserved rather than lossily converted through UTF-8. %A is read back as the result, including when it is empty.
  • %L: the conflict-marker length for this merge depth.
  • %P, %S, %X, %Y: the worktree-relative path and the ancestor, ours, and theirs labels, each shell-quoted with Git's single-quote rules. %% expands to a literal percent sign.

Exit status 0 reports a clean merge; 1 through 128 reports a conflict and keeps the bytes the driver left in %A; a higher status or failure to start the shell is fatal, after which Libra performs no merge-driven HEAD, index, or tracked working-tree update. Because the driver is unsandboxed, changes that the configured command makes directly to repository files or metadata are outside Libra's rollback boundary. Driver stdout/stderr is discarded; Libra's error names the driver, path, and config key without echoing the configured command. The input files live in a mode-0700 worktree-local directory (files are private), are removed when the driver returns or the child is interrupted, and do not use predictable names. If Libra itself is terminated before it can unwind, a residual directory stays private under mode 0700. A driver also owns its result under -X ours / -X theirs. Recursive virtual-ancestor merges invoke the same driver with merged common ancestors / Temporary merge branch … labels; merge.<name>.recursive is not implemented.

The built-in dispatch is also used by merge-file, cherry-pick, and revert; those commands do not execute external merge drivers yet. merge-file outside a Libra repository has no attribute/config source and always uses text.

Input normalization

The default three-way strategy accepts four comparison-only whitespace options: -X ignore-space-change, -X ignore-all-space, -X ignore-space-at-eol, and -X ignore-cr-at-eol. They use the same line normalizers as libra diff. The built-in text/union merge compares canonical lines, then writes the original text back; lines newly selected from the merge use ours-side line endings. Binary inputs and the explicit binary driver are not rewritten. These xdiff-style flags do not alter the files passed to an external merge driver.

merge.renormalize=true or -X renormalize canonicalizes all three content inputs according to each path's text / eol attributes before either a built-in or external low-level driver runs. -text disables conversion, text=auto converts non-binary input, and a set/value text attribute or eol=lf|crlf enables text conversion. Libra currently implements only this built-in line-ending conversion; arbitrary clean/smudge filter programs remain unsupported. The merged result is backfilled to original text and ours-side line endings. -X no-renormalize disables the configured default.

-X is repeatable. The final ours/theirs choice and final renormalize/no-renormalize toggle win independently; multiple whitespace modes select the strongest comparison (ignore-all-space, ignore-space-change, ignore-space-at-eol, then ignore-cr-at-eol). An explicit renormalize toggle overrides even an invalid configured value. Otherwise merge.renormalize is read strictly only when a real three-way merge is required: invalid values fail before HEAD/index/worktree/merge-state mutation, while fast-forward and already-up-to-date merges do not consume the setting. libra pull inherits the configured default on its merge path but exposes no -X option.

Directory/file collisions (D/F conflicts)

When one side keeps (or edits) a file foo while the other side turns foo into a directory — deleting the file and adding paths beneath foo/ — the two cannot share one path. Libra follows Git's recursive strategy (merge-ort.c, unique_path): the directory keeps foo, and the file is written under a unique name derived from the branch that holds it — foo~HEAD when the file is ours, foo~<branch> (with / in the branch name replaced by _) when it is theirs; if that name is already used by any input of the merge or by its result — as a file or as a directory, and a path only the merge base had counts too, exactly the set Git's unique_path checks — _0, _1, … is appended. The merge stops as a conflict (LBR-CONFLICT-002) and prints Git's line first:

CONFLICT (file/directory): directory in the way of foo from HEAD; moving it to foo~HEAD instead.

The moved file is the unmerged path: the index records it at the new name with the file's own side on stage 2 (ours) or stage 3 (theirs) and, when the merge base tracked a file at foo, that file on stage 1; there is no stage 0 entry, and, for a non-squash merge, merge-state.json lists the new name in conflicted_paths. The directory's contents merge normally. Two shapes exist, both as in Git: a file only one side added is a pure file/directory conflict — written verbatim at the new name, reported as file-directory by --dry-run; a file the merge base tracked and the file side edited is a modify/delete conflict that merely moves — the new name carries the base (stage 1) and the editing side, --dry-run reports it as modify-delete with original_path, Git's second line is printed too (CONFLICT (modify/delete): foo~HEAD deleted in <branch> and modified in HEAD. Version HEAD of foo~HEAD left in tree.), and the file is left verbatim at the new name, as that line says. A file one side left untouched while the other replaced it with a directory is a plain clean deletion: no conflict, no message. A directory holding nothing but empty trees counts as in the way only when the merge base had nothing at that path — Git adopts such a new directory verbatim, while a directory the base already had is traversed, found to contain no file, and leaves the file where it is (a plain modify/delete). Both cases match git merge on crafted trees. Under --json/--machine none of these lines is printed: stdout stays machine-clean and the conflict is the error envelope on stderr. A strategy option (-X ours / -X theirs) settles content hunks only: a modify/delete under a directory stays a conflict, as in Git. The merge never writes or deletes through a symbolic link in the working tree — an ignored foo -> elsewhere standing where foo/… must be written, or above a tracked file the merge removes, refuses the whole merge before anything changes — while a symlink sitting exactly where the moved file goes is replaced by the file, and a tracked symlink foo giving way to a directory foo/ moves to foo~HEAD like any file. Only paths the merge tracks right now are ever removed: an untracked file that happens to carry a historical name stays. For a non-squash merge, resolve it by editing the foo~… file if you want to keep it, staging it with libra add foo~… and running libra merge --continue; or run libra merge --abort, which restores foo as it was before the merge and removes both the moved copy and the directory the merge created (directories the merge emptied are pruned, so a nested foo/a/ never blocks the file's return). Discarding the moved file instead of keeping it is not yet possible: libra rm does not accept an unmerged path, so the non-squash recovery described here is --abort (Git resolves that case with git rm foo~HEAD). For a squash conflict, edit and stage the same moved path, then use a plain libra commit; merge control actions are unavailable because no merge state was recorded.

A directory that merges to nothing (every entry beneath it was deleted by the file's side and untouched by the other) is not in the way: the file keeps its path, as in Git. Inside a recursive criss-cross fold (see above) the same rule applies without asking: the file moves to foo~Temporary merge branch 1 (or 2) in the virtual ancestor, exactly as Git does at call_depth > 0, so the ancestor tree never holds a blob and a subtree under one name.

Only collisions between the two sides' tracked contents are handled here. An untracked foo or foo~HEAD in the working tree that the merge would overwrite is refused up front by the existing untracked-overwrite check. An ignored file is expendable and gets replaced, exactly as git merge treats it — whether it sits at one of these names or where the merge has to create a directory. If you keep something precious under an ignore rule at a path a merge may write, it is not protected. Renames are detected (see "Renames" below), but a collision created by a rename — a rename whose destination is the directory in the way, or the source of one — is left to the ordinary delete-plus-add handling for now.

Renames

A file one side renamed while the other side changed it in place merges as one file: Libra runs rename detection once per side of the merge (base to ours and base to theirs, the same engine diff and status use), and the other side's change follows the file to its new path. A conflict is presented at the new path too, with the merge base's version of the original path on stage 1.

merge.renames turns detection off (falling back to diff.renames; false makes a rename look like a delete plus an add again), and merge.renameLimit caps how many added or deleted paths each side may have before the expensive similarity stage is skipped (falling back to diff.renameLimit, default 7000). A value of 0 or less means that default rather than "no cap". Git does the same for the values it supports — 0 and -1, its own "unset" sentinel — but anything below -1 trips an assertion inside Git and aborts the process, which Libra deliberately does not reproduce: it accepts every non-positive value and uses the default. Only a value that is not an integer at all is an error. Past the cap the merge still completes: exact renames are still paired and a notice says the rest was skipped. Libra applies the cap per side — it skips the expensive stage once either side exceeds it — where Git compares the whole matrix and counts only the sources the merge actually needs, so Git keeps detecting in some shapes where Libra stops.

Both keys are read strictly: a value neither can parse fails the merge before anything is written, including before --autostash saves your changes. That check runs exactly where Git parses these keys, so a fast-forward, an already-up-to-date merge, -s resolve, -s ours, and --squash or --no-commit over a fast-forwardable history all succeed regardless of the value. Resolve deliberately does not consume rename configuration; --no-ff with ort/recursive on that same history is a real rename-aware merge and fails.

A rename is a move of one thing into another name, so both ends must be the same kind of entry. If the other side replaced the file at the old path with a symbolic link, the rename cannot use it: the merge base still follows the rename to the new path, which conflicts there as a modify/delete, but the link SURVIVES under the old name and no rename/delete is reported — Git takes its own type-change path for this, and so does Libra.

A destination is "occupied" only by what survives the merge. A path the merge base held but neither side kept is gone, and so is one the other side merely carries unchanged from the base, because the renaming side had to clear the destination to put a file there. In both cases the rename is used, as git merge does. What does stand in the way is content the other side added or changed there, which survives as its own entry or as a conflict.

A destination nested beneath the renamed file's own former path — old renamed to old/new — is not a collision at all: the rename itself frees the name, so the rename is used and the other side's edit follows the file to old/new. git merge and git merge-tree --messages both merge that shape cleanly, with no CONFLICT (file/directory) line.

Both sides renaming the same file to the same path is not a conflict at all: the merge base follows the file to that path and the two contents merge there normally, so a rename both sides agreed on can come out clean.

The remaining shapes are Git's path-level rename conflicts:

  • rename/rename — both sides renamed the same file to different paths. Both destinations are kept and normally hold the same merged content. Some unresolved binary conflicts instead retain each side's original entry at its own destination, matching Git's fallback when both the merged hash and mode equal ours' original entry. Content selection does not discard an independently merged executable mode. The merge reports CONFLICT (rename/rename): <old> renamed to <a> in HEAD and to <b> in <branch>. The original name is resolved by removal. Git instead leaves it unmerged at stage 1 — its own source comment calls that a legacy behaviour kept only for its regression tests, and says removing it is "the consistent" thing to do. Libra takes the consistent branch. Keeping the entry would also put the conflict out of reach of the ordinary staging flow — the original name has no working-tree file, and libra add, libra rm and libra restore --staged all match paths through the staged entry, so none of them can address it. It would still be resolvable, through libra read-tree HEAD followed by libra add -A ., or through libra update-index --cacheinfo; both are blunt instruments — the first replaces the whole index and discards every resolution staged so far, the second is plumbing.
  • rename/delete — one side renamed the file, the other deleted it. The new path is kept with the renaming side's content and the base recorded beside it, and the merge reports CONFLICT (rename/delete): <old> renamed to <new> in HEAD, but deleted in <branch>. This is a conflict even when the rename changed nothing about the content.
  • rename/add, and a rename whose destination another rename took — the rename's own three-way merge runs first, and its result then collides with whatever the other side put at that path, so the destination is reported as an add/add conflict with no common ancestor. When the rename's own merge did not come out clean the merge additionally reports CONFLICT (rename involved in collision): rename of <old> -> <new> has content conflicts AND collides with another path; this may result in nested conflict markers.

Conflict markers a rename-involved merge writes are one character longer than an ordinary content conflict's, and each side is labelled <branch>:<path> rather than by branch alone — only the side that actually renamed carries the destination path, the other keeps the source. Both match Git. Under merge.conflictStyle=diff3 the common-ancestor marker is qualified with the source path too; Libra writes it as base:<path>, keeping the base label its diff3 output has always used, where Git uses the abbreviated ancestor commit id instead (an intentional output difference).

Directory renames are inferred at the outer merge. When every tracked path has left an old directory and one destination directory has the unique highest number of file-renames, an addition made by the other side below the old name follows that directory rename. A modification to an existing base path already follows its ordinary per-file rename. A destination tie is a directory-rename split: the additions stay at their old names as resolved stage-0 entries, but the merge stops so the user can confirm the layout; merge --continue can commit that layout immediately, or merge --abort can restore the old HEAD.

merge.directoryRenames=false disables this inference. true moves an affected addition automatically and reports Path updated: ...; conflict (the default) moves it to the suggested destination but leaves that path unmerged and reports CONFLICT (file location): .... If the suggested target is independently occupied, normal add/add conflict handling retains both sides. Disabling merge.renames disables directory inference too.

Libra accepts conflict plus Git-compatible boolean spellings for true and false (including yes/no, on/off, and numeric booleans), and rejects any value outside those three logical modes before repository writes with LBR-REPO-003. This fail-closed parsing is an intentional safety difference from Git, which currently ignores unknown merge.directoryRenames values and retains its default. Human directory messages are suppressed in JSON/machine mode; a suggested-location or split preview uses conflict kind directory-rename.

History-changing merge defaults

When the corresponding CLI flag is absent, Libra reads these Git-compatible defaults through the local → global → system cascade:

  • merge.ff=true|false|only allows fast-forwarding, forces a merge commit, or rejects a non-fast-forward merge. --ff, --no-ff, and --ff-only override it and are last-one-wins among themselves (the last FF flag on the command line decides). only (like --ff-only) rejects only a genuinely diverged single-head history; a non-up-to-date octopus never fast-forwards.
  • merge.log=true|false|<n> appends up to 20 (for true) or <n> target-side commit subjects to the generated merge message. --log[=<n>] and --no-log override config and are last-one-wins; bare --log means 20. An explicit -m suppresses config-only merge.log, while an explicit --log still appends the shortlog to the custom message. For a non-squash merge, the resolved message is recorded in merge state, so a merge finished later with merge --continue commits with the same message and shortlog. Squash records no merge state; its ordinary libra commit supplies the commit message.
  • merge.verifySignatures=true|false controls tip-signature verification; --verify-signatures and --no-verify-signatures override it. Verification runs on every resolved target before any mutation — including autostash creation — so a rejected merge writes nothing (no stash entry, no objects). --verify-signatures accepts any certificate in the repository allowlist (the active key, the generated fallback, and archived vault.gpg.history.<FPR>.pubkey entries), so a tip signed before a key rotation stays verifiable, while a tip signed by a key this repository never imported is refused. Revocation and expiry are evaluated at the signature's own creation time: a tip signed while the key was still valid keeps verifying, while a signature made after the key was revoked or had expired is refused.
  • commit.gpgSign=true|false controls merge-commit signing. -S/--gpg-sign force vault signing, and --no-gpg-sign disables it. Without either flag, commit.gpgSign wins over the vault.signing fallback. The resolved choice is persisted for --continue and --restart; old merge state without it reuses the current default. A vault-signing failure leaves HEAD unmoved and writes no merge commit.
  • --signoff appends Signed-off-by: <committer name> <committer email> after the final merge message has been processed. The initial choice is persisted across a conflict or --no-commit --continue; a matching Git-qualifying trailer is not duplicated. Merge has no -s short form because -s selects a merge strategy. The flag is unavailable with --abort, --restart, --squash, or --dry-run, which cannot create a merge commit.

Invalid or unreadable local/global values fail before HEAD, index, worktree, or merge-state mutation: an unusable value is LBR-CLI-002 for merge.ff and merge.verifySignatures and LBR-REPO-003 for merge.autostash, merge.conflictStyle, merge.renames, merge.renameLimit, merge.directoryRenames, and merge.renormalize, while a value that cannot be read at all is LBR-IO-001. Encrypted local/global values are decrypted; unreadable or unsupported system scope is skipped. Exception: a global config store whose schema is newer than this Libra binary is skipped with a one-time deduplicated warning instead of failing (see LBR-CONFIG-001). merge.renormalize follows the phase-local timing described above.

Libra is a monorepo client and never merges submodule content. A three-way merge treats gitlinks in two tiers:

  • The merge would have to arbitrate the gitlink — any side records a different commit id than the merge base, including a side that added or removed the entry. The merge is refused before anything is written (no merge state, no index or working-tree change, HEAD unmoved) with LBR-UNSUPPORTED-001 naming the path:

    error: merge would have to merge the submodule (gitlink) entry 'vendor': Libra does not support submodules
    

    Resolve the submodule pointer outside Libra, or drop the gitlink entry from the branches being merged.

  • All three sides record the same commit id — nothing has to be decided, so the pointer is carried into the merge result verbatim. (Previously such entries were silently dropped, which deleted the submodule from the merged tree.)

libra rebase and libra cherry-pick share the same guard and the same wording, with rebase / cherry-pick in place of merge.

Libra still does not implement external merge strategies, subtree, explicit -s octopus, or strategy options outside the values listed above. Commit signing and signature verification are limited to the local vault PGP key; external GPG keyrings and SSH signing are not supported. Verification accepts any certificate in the repository allowlist (active key, generated fallback, archived vault.gpg.history.<FPR>.pubkey entries) and evaluates revocation and expiry at the signature's own creation time.

Worktree materialization is mode-aware (plan issues/470 FM-02): files are created with the entry mode's permission bits (100755 -> 0777, 100644 -> 0666) under the process umask, replaced atomically through a same-directory temp file, and the index/tree entries keep the mode (100755/100644/120000).

Options

When core.sparseCheckout=true this command fails closed with LBR-UNSUPPORTED-001: it would rewrite the working tree (or the index/stash) around the whole tree instead of the sparse view (sparse cone materialisation is not implemented yet).

Option Description
<branch>... One or more target branches, commits, or remote-tracking refs. Two or more select the atomic octopus path.
-m, --message <MSG> Override the merge commit message (default Merge <branch> into <head>). Also accepted with --continue, where it overrides the message recorded when the conflicted merge started — a Libra extension, since Git's --continue takes no arguments.
-F, --file <FILE> Read the merge message from a file. It is mutually exclusive with -m, and may also override the saved message during --continue.
--into-name <NAME> Use NAME as the destination in an automatically generated message (Merge <branch> into <NAME>). It does not alter an explicit -m/-F message and is unavailable with --continue.
-e, --edit Open $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR on the resolved message. Libra does not edit by default; an empty edited result aborts before merge state or a commit is written. Available with --continue.
--cleanup=<MODE> Use strip, whitespace, verbatim, scissors, or default message cleanup. Without editing, default and scissors use the shared whitespace behavior; cleanup occurs before --signoff.
--ff Allow fast-forwarding when possible, overriding `merge.ff=false
--ff-only Refuse unless a single-head merge can fast-forward. A non-up-to-date octopus merge is never a fast-forward and is refused.
--no-ff Always create a merge commit even when a single-head fast-forward is possible. Octopus already always creates one.
-s <strategy>, --strategy=<strategy> Select ort (single-head default), its recursive alias, conservative resolve, or ours. Repeatable for a single target: try in order, first clean result wins, otherwise replay the lowest Git evaluate_result score (later tie wins). With several targets only automatic octopus (no -s) or one -s ours is supported. Cannot be combined with -X.
-X <option>, --strategy-option=<option> Accepts ours, theirs, ignore-space-change, ignore-all-space, ignore-space-at-eol, ignore-cr-at-eol, renormalize, or no-renormalize. Repeatable; favor and renormalize toggles are last-one-wins, while whitespace modes select the strongest requested comparison. Cannot be combined with -s.
--allow-unrelated-histories Permit histories with no common ancestor by using a virtual empty merge base. The permission is persisted for non-squash conflict --restart.
--log[=<N>] Append up to N target-side subjects to the merge message; bare --log uses 20. Overrides merge.log, and also appends to an explicit -m message. Last-one-wins with --no-log.
--no-log Disable the merge-message shortlog, overriding merge.log and an earlier --log.
--squash Produce the merged index/working tree but create no commit, do not move HEAD, and record no merge state, including on conflict. Resolve and stage any conflicts, then finish with a plain libra commit (one parent). --continue, --abort, and --restart report no merge in progress.
--no-commit Perform the merge but stop before committing. A clean octopus state retains every target for --continue/--abort; an octopus conflict is atomic and creates no state. Single-head conflicts retain their normal resolvable state.
--no-verify Skip all .libra/hooks for this merge. With --continue, bypass the pending commit/message/post hooks.
--no-edit Accept the resolved merge message without launching an editor (the default). Mutually exclusive with --edit.
-v, --verbose Be verbose: print the merge result's diffstat (Git passes -v to the strategy, which renders it). Equivalent to --stat; --no-stat still suppresses it.
--stat Show a diffstat of the merge result (the changes between the pre-merge HEAD and the new commit) after the merge completes. Git shows this by default; Libra defaults to no diffstat, so --stat opts in. Last-one-wins toggle with --no-stat/-n. Human output only.
-n, --no-stat Do not show a diffstat at the end of the merge (Libra's default). Last-one-wins toggle with --stat.
--no-progress Do not show a progress meter. No-op accepted for Git parity: Libra's merge never renders a progress meter.
--verify-signatures Verify the PGP signature on every target tip and abort before mutation if any is unsigned or bad. Overrides merge.verifySignatures; signatures made by any public key this repository has ever configured (active, generated, or historical) are validated.
--no-verify-signatures Do not verify the merged commit's signature, overriding merge.verifySignatures=true. The inverse of --verify-signatures; the last one wins.
--rerere-autoupdate, --no-rerere-autoupdate Override replay staging for this merge: positive stages a replayed resolution, negative leaves it unstaged; the last supplied flag wins. Omit both to inherit rerere.autoUpdate. Rerere identifies a conflict from its normalized hunk sides and only writes a replay after its three-way application is clean. The explicit choice is retained in merge state so a later merge --continue preserves it. Both are no-ops while rerere is disabled.
--signoff Append Signed-off-by: <committer name> <committer email> after the final merge message. The initial request is retained by merge state for --continue; a matching final trailer is not duplicated. There is no -s alias because -s selects a strategy.
-S, --gpg-sign Force vault-signing of the merge commit. This applies to automatic, -s ours, octopus, and --continue commit paths.
--no-gpg-sign Do not vault-sign the merge commit. This overrides commit.gpgSign and vault.signing; together with -S it is a last-one-wins toggle.
--continue Finish an in-progress non-squash merge after conflicts have been resolved and staged, using the parent set recorded in merge state. A squash has no merge state to continue.
--abort Restore the pre-merge HEAD, index, and working tree of an in-progress non-squash merge (re-applies a held autostash). Unavailable after --squash.
--quit Forget an in-progress non-squash merge without resetting HEAD, the index, or the working tree. It removes merge state only, so conflict stages and markers remain. A held autostash is promoted to the visible stash list, not re-applied; --quit takes no branch or other merge option.
--autostash / --no-autostash Stash local tracked changes before the merge and restore staged index and unstaged worktree layers separately when it concludes — held (outside stash list) across a non-squash conflict until --continue/--abort, or promoted to the visible stash list by --quit or by a whole-tree libra reset that clears the in-progress merge. A clean squash attempts restoration when the merge command returns. A conflicted squash saves the autostash directly in stash list without applying it, preserving the unresolved index and working tree; resolve and commit those conflicts, then run libra stash pop. If saving fails, a warning is emitted and the held autostash remains referenced by its sidecar. A conflicting re-apply is saved to the stash list with a notice, never lost. Config: merge.autostash (boolean; invalid value = hard error). Untracked files are not stashed (Git parity). --json adds autostash: applied|stashed|kept.
--dry-run Libra extension: preview the merge outcome writing nothing — reports fast-forward / already-up-to-date / clean selected strategy / would-conflict (with the paths). Exits 0 for a clean preview, 1 when the merge would conflict. Mutually exclusive with --continue/--abort/--quit/--restart/--squash/--no-commit/--edit.
--restart Libra extension (ports Lore's branch merge restart): abort the in-progress conflicted merge — discarding any resolution work, exactly like --abort — then immediately re-run the same merge against the recorded target commit and selected strategy, regenerating fresh conflict markers and state. Takes no branch and no merge options. Recovery-critical --allow-unrelated-histories is also replayed; presentation/policy options such as the original -m/--no-ff are not. Requires a conflicted non-squash merge: squash has no merge state to restart, and a staged --no-commit merge is refused (finish it with --continue or discard with --abort).
--json Emit a structured success envelope. selected_strategy names the concrete backend when one ran; the existing strategy field remains the outcome category.
--machine Emit the same structured envelope as one compact JSON line.
--quiet Suppress human success output.

--ff, --no-ff, and --ff-only form a last-one-wins group (Git's OPT_SET_INT semantics): the last flag on the command line decides, and any of them overrides merge.ff. For example, libra merge --ff-only --no-ff topic creates a merge commit even when a fast-forward is possible.

Repository hooks

pre-merge-commit blocks an automatic merge commit (including --continue) but does not run for fast-forward, squash, or a pending --no-commit result. Automatic merge commits then run prepare-commit-msg <file> merge, commit-msg <file>, and advisory post-commit; message hooks may modify .libra/COMMIT_EDITMSG. post-merge runs advisory after a completed merge/fast-forward with argument 0, or after squash with argument 1; it does not run for already-up-to-date or conflicted outcomes. --no-verify skips every hook in that merge lifecycle. Pull uses the same lifecycle; use LIBRA_NO_HOOKS=1 when an explicit bypass is required. See Repository hooks for the sandbox and failure contract.

Common Commands

libra merge feature-x
libra merge topic-a topic-b topic-c
libra merge -s resolve -s ort feature-x
libra merge -X ours feature-x
libra merge -s ours obsolete-history
libra merge --allow-unrelated-histories imported-root
libra merge --log=10 feature-x
libra merge refs/remotes/origin/main
libra merge --continue
libra merge --continue -m "merge: reconcile release notes"
libra merge --abort
libra merge --dry-run feature-x
libra merge --restart
libra merge --json feature-x

Conflict Lifecycle

For a merge started without --squash (including --no-commit), resolve conflicts as follows:

  1. Edit files containing conflict markers.
  2. Stage each resolved path with libra add <path>.
  3. Run libra merge --continue to create the merge commit.

Run libra merge --abort before continuing to restore the branch, index, and working tree to the pre-merge commit. libra status shows the in-progress merge target and the continue/abort commands while merge state exists.

This conflict-resolution flow applies to single-head merges. An octopus content conflict is rejected atomically and creates no merge state, so --continue, --abort, and --restart do not apply; merge the heads one at a time instead. A clean octopus stopped with --no-commit does create state and may be continued or aborted normally.

To throw away a botched resolution attempt and start over in one step, run libra merge --restart: it restores the pre-merge state exactly like --abort (any edits to conflicted files are discarded) and immediately re-runs the same merge against the recorded target commit — deterministic even if the branch has moved since — leaving fresh conflict markers and a fresh merge state. The re-run uses default merge options.

A --squash conflict keeps the unresolved index stages and working-tree result with HEAD unchanged, but creates no merge state. Resolve the files, stage each resolved path with libra add <path>, and run a plain libra commit to create a single-parent commit. libra merge --continue, --abort, and --restart all fail with no merge in progress (LBR-REPO-003, exit 128); the non-squash recovery steps above do not apply. With --autostash, local changes are saved directly in stash list so the unresolved index and working tree stay intact; resolve and commit the squash, then use libra stash pop to restore them.

Dry Run

libra merge --dry-run <branch>... (a Libra extension — Git has no true merge dry-run) reports what the merge would do without writing anything: no HEAD, index, working-tree, reflog, merge-state, or object-store mutation (auto-merged blobs are computed in memory only). Because it is read-only it also works on a dirty working tree, provided the index has no unresolved entries and no merge is already in progress. The entry checks still apply to --dry-run, including unresolved squash conflicts; apart from those checks, the preview does not validate cleanliness, so a real merge may still refuse where the preview succeeded.

Outcomes and exit codes:

Preview outcome Human output Exit
Fast-forward possible Would fast-forward 0
Already up to date Already up to date. 0
Clean three-way/ours/octopus merge Would merge cleanly by the '<strategy>' strategy. 0
Would conflict Would conflict in: <paths> (a directory/file collision is listed under the ~-suffixed name the file would be moved to) 1

The would-conflict exit of 1 is an outcome signal (like merge-file and diff --exit-code), deliberately distinct from the 128 a real conflicting merge exits with — the preview itself succeeded. With --json/--machine the summary carries "dry_run": true and, when conflicting, "would_conflict": true plus conflicted_paths and conflict_kinds — one {"path", "kind", "original_path"?} object per conflicted path, kind being content, modify-delete, file-directory, rename-rename or directory-rename; rename-rename reports both destinations of a rename/rename(1to2), while directory-rename reports a suggested location or directory split. original_path is present only for a directory/file move (the path the file held before; path is then the ~-suffixed name it would be written to, and conflicted_paths lists that same name). All of these keys are absent from every real merge's output (frozen schema).

Human Output

Fast-forward:

Fast-forward

Clean default single-head merge:

Merge made by the 'ort' strategy.

Ours strategy:

Merge made by the 'ours' strategy.

Already up to date:

Already up to date.

After --continue:

Merge completed.

After --abort:

Merge aborted.

Conflict errors are printed through Libra's standard structured error envelope on stderr and include recovery hints.

JSON / Machine Output

Success output keeps the historical files_changed numeric field and adds merge-lifecycle fields only when relevant.

{
  "ok": true,
  "command": "merge",
  "data": {
    "strategy": "three-way",
    "selected_strategy": "ort",
    "old_commit": "abc1234...",
    "commit": "def5678...",
    "files_changed": 2,
    "up_to_date": false,
    "parents": ["abc1234...", "fedcba9..."]
  }
}

selected_strategy is additive: existing consumers can continue switching on strategy, whose outcome-category values do not change. Default and explicit single-head three-way merges name ort, recursive, or resolve; -s ours uses both strategy: "ours" and selected_strategy: "ours"; and a default multi-target merge uses strategy: "octopus" plus selected_strategy: "octopus". The field is omitted when no backend runs (fast-forward, already-up-to-date, or abort). parents contains HEAD followed by every non-redundant target in command-line order. Already-up-to-date merges use strategy: "already-up-to-date", commit: null, files_changed: 0, and up_to_date: true.

--abort sets aborted: true; --continue sets continued: true. Conflict failures return an error envelope on stderr with LBR-CONFLICT-002. --dry-run adds dry_run, would_conflict, conflicted_paths and conflict_kinds (see Dry Run).

Parameter Comparison: Libra vs Git vs jj

Parameter Libra Git jj
Branch target <branch>... (one or more) <commit>... (one or more) N/A (use jj new)
Fast-forward Supported Supported N/A
Single-head three-way Supported Supported N/A
Criss-cross (several merge bases) Recursive virtual ancestor (fold order: ascending object id; max depth 20, max 32 bases per level) Recursive virtual ancestor (-s recursive/ort, unbounded depth) N/A
Continue / abort / quit --continue, --abort, --quit (non-squash merge state required; quit preserves the checkout) --continue, --abort, --quit N/A
Octopus merge Supported; atomic conflict refusal, ordered reduced parents Supported N/A
Fast-forward only --ff-only --ff-only N/A
Force merge commit --no-ff --no-ff N/A
Squash --squash; resolve/stage conflicts, then plain commit (one parent) --squash; resolve/stage conflicts, then plain commit (one parent) N/A
No-commit --no-commit --no-commit N/A
Skip all merge-lifecycle hooks --no-verify --no-verify N/A
Commit message -m <msg>, -F <file>, --into-name <name> Same message-source surface N/A
Edit / cleanup message -e/--edit, --cleanup=<mode>; edit is opt-in Same surface N/A
No editor --no-edit (default; conflicts with --edit) --no-edit N/A
Post-merge diffstat --stat (prints it); -n / --no-stat (default: omit) --stat (default) / -n / --no-stat N/A
No progress meter --no-progress (no-op; never renders one) --no-progress N/A
Disable signature verification --no-verify-signatures (default; disables --verify-signatures) --no-verify-signatures N/A
Rerere autoupdate --rerere-autoupdate / --no-rerere-autoupdate override replay staging (last wins); omit to inherit rerere.autoUpdate Same toggle surface Choice persists across --continue
Signoff trailer --signoff (no short form; -s selects a strategy) --signoff (no short form; -s selects a strategy) Matching final trailer is not duplicated
Merge commit signing -S / --gpg-sign forces vault signing; --no-gpg-sign disables it Same toggle surface Vault-only; no external GPG/SSH signing
Default / recursive strategy -s ort (default), -s recursive alias -s ort (default), -s recursive N/A
Resolve strategy -s resolve (one base, no virtual ancestor or rename handling) -s resolve N/A
Repeated strategy fallback Supported for one target; first clean, otherwise lowest evaluate_result score Supported N/A
Ours strategy -s ours -s ours N/A
Conflict-side preference -X ours/theirs -X ours/theirs N/A
Whitespace-aware content merge -X ignore-space-change / ignore-all-space / ignore-space-at-eol / ignore-cr-at-eol Same N/A
Renormalized content merge merge.renormalize / -X renormalize / -X no-renormalize Same Libra does not run arbitrary clean/smudge filters
Unrelated histories --allow-unrelated-histories Supported N/A
Merge-message shortlog --log[=<n>] / --no-log Supported N/A
Other custom strategies/options Not supported Supported N/A
Verify signatures --verify-signatures (repository-configured public keys) --verify-signatures N/A
JSON output --json / --machine Not supported N/A

Error Handling

Scenario StableErrorCode Exit
Missing branch / action LBR-CLI-001 129
Target ref cannot be resolved LBR-CLI-003 129
Failed to load merge target/current commit/tree LBR-REPO-002 128
Unrelated histories without --allow-unrelated-histories LBR-REPO-003 128
Three-way merge would have to arbitrate a 160000 gitlink (submodule) LBR-UNSUPPORTED-001 128
Recursive virtual ancestor would nest deeper than 20 levels or fold more than 32 bases at one level LBR-UNSUPPORTED-001 128
Unknown -s / -X value or mutually exclusive strategy options LBR-CLI-002 129
A single-head strategy (or repeated strategies) is requested for several targets LBR-UNSUPPORTED-001 128
--verify-signatures: any target tip unsigned, signature invalid, or vault unavailable LBR-REPO-003 128
Merge conflicts LBR-CONFLICT-002 128
Octopus conflict (atomic; no merge state) LBR-CONFLICT-002 128
Unresolved index entries without merge state, even for an up-to-date merge or --dry-run LBR-CONFLICT-002 128
Dirty worktree or staged changes LBR-CONFLICT-002 128
Untracked file would be overwritten LBR-CONFLICT-002 128
Merge already in progress LBR-CONFLICT-002 128
No merge in progress for --continue / --abort / --restart (including after --squash) LBR-REPO-003 128
Unsupported merge.conflictStyle value (e.g. bogus) when rendering a conflict LBR-REPO-003 128
Invalid merge.renormalize value when a real three-way merge consumes it LBR-REPO-003 128
Unresolved conflict stages remain for --continue LBR-CONFLICT-002 128
Failed to read merge state or index LBR-IO-001 128
Failed to save state, index, tree, commit, HEAD, or worktree LBR-IO-002 128

Issue #477 notes

  • reset clears an in-progress merge and moves its autostash into the stash list
  • a plain commit concludes the in-progress merge
  • conflict markers name the merge target as it was typed

clone --separate-git-dir pointer layout: when <worktree>/.libra is a gitdir: pointer file, this command is refused with LBR-UNSUPPORTED-001 before any index, HEAD or ref write. Only status, log, cat-file, the no-argument branch listing, alternates list, clone, upgrade, ui, login, whoami, logout and completions run in that layout.