libra cherry-pick
Command reference for `libra cherry-pick`
Apply the changes introduced by some existing commits.
Alias: cp
Synopsis
libra cherry-pick [-n|--no-commit] [-x] [-s|--signoff] [-e|--edit]
[-m <n>|--mainline <n>] [--ff] [-S|--gpg-sign]
[-X <ours|theirs>] [--rerere-autoupdate | --no-rerere-autoupdate]
[--allow-empty] [--allow-empty-message] [--keep-redundant-commits]
[--empty=<mode>] [--cleanup=<mode>] [--json] [--quiet] <commit>...
libra cherry-pick (--continue | --skip | --abort | --quit)
Description
libra cherry-pick applies the changes introduced by the specified commits onto the current branch. For each named commit, Libra computes the diff between that commit and its parent, applies the resulting changeset to the current index and working tree, and (unless --no-commit is given) records a new commit.
This is useful for selectively applying commits from one branch to another without merging. When multiple commits are supplied they are applied in the order given, each one becoming a new commit on the current branch before the next is processed.
The command works on a branch or on a detached HEAD, like Git: a pick started on a detached HEAD commits onto it and advances the detached ref (no branch is moved), and a sequence started there records HEAD as its head_name, so --continue and --abort keep operating on the detached ref (abort restores the commit HEAD pointed at when the pick started). Non-merge commits are applied directly; merge commits require -m <parent-number> to choose which parent to diff against.
Auto-committed picks preserve the source commit's author metadata (name, email,
author date, and timezone). The committer is the current identity/date, honoring
GIT_COMMITTER_* overrides. Signed source messages are de-signed before message
cleanup/trailer handling, so gpgsig blocks never become the replayed subject.
Submodules are never merged (see docs/commands/merge.md): if the pick's three-way inputs (the parent tree, the current index, and the picked tree) record different 160000 gitlink object ids, the cherry-pick is refused before anything is written, with LBR-UNSUPPORTED-001 and a message naming the path (cherry-pick would have to merge the submodule (gitlink) entry '<path>': Libra does not support submodules). A gitlink all three sides agree on is left untouched instead of being dropped from the picked change set.
When a commit cannot be applied cleanly, Libra performs a three-way apply (base = parent tree, ours = current index, theirs = picked tree) and writes any unresolved divergent path to the index (stages 1/2/3) and the working tree (line-level conflict markers, matching Git). -X ours/theirs can resolve only the overlapping hunks while retaining clean changes. The in-progress sequence is persisted in the unified SQLite sequence_state table, so you can resolve a remaining conflict and continue with --continue, drop the conflicted commit with --skip, or undo the whole sequence with --abort/--quit. --quit only forgets the sequence and is idempotent: with nothing in progress it exits 0 and leaves the index and working tree untouched (Git behaviour), while --abort requires a sequence (no cherry-pick in progress, exit 128). While a cherry-pick sequence is in progress, other sequencer operations are blocked (LBR-CONFLICT-002).
A new cherry-pick refuses to start while the index has unmerged entries: before resolving any target or writing to the index, working tree, refs, or sequence state, it exits 128 with LBR-CONFLICT-001 and names up to ten unmerged paths (Git refuses the same way). Resolve each path and libra add it, or discard the conflict with libra reset --hard, then rerun the cherry-pick; the refusal starts no sequence, so --continue, --skip, --abort, and --quit do not apply to it. A conflicting -n/--no-commit pick also leaves no sequence to continue: resolve the paths, libra add (or libra rm) them and run libra commit, or discard the staged pick with libra reset --hard. A pick that would overwrite an untracked working tree file is refused before that commit writes anything: move or remove the named file, then run the command again; when earlier commits of a commit-per-pick sequence already landed, run libra cherry-pick --continue instead (it re-attempts the stopped commit; Git drops it); when earlier picks of a --no-commit run are staged, no sequence exists, so pick the remaining commits again with -n or discard everything with libra reset --hard.
A commit-per-pick run of several commits records its sequence before the first commit is applied and moves it forward with every commit it applies (in the same database transaction as the branch update, or, for a --ff fast-forward, through a recovery marker written just before the reset), so an interrupted run, or one that stops on a non-conflict error after earlier commits landed, stays in progress: finish it with libra cherry-pick --continue, --skip or --abort. --ff carries over to the commits that --continue and --skip apply. --skip and --abort record themselves before resetting; if one is interrupted, run the same command again to finish it, and until then --continue refuses with LBR-REPO-003.
That content merge honors the path's merge gitattribute and the
merge.default fallback exactly as libra merge does: text, binary, and
union are built in, while unknown names fall back to text. A union driver
can therefore resolve an overlapping pick by keeping current content followed
by picked content; a binary-driver conflict keeps the complete surviving side
(current when present) without adding text markers.
A stopped pick does not outlive the working tree it stopped in: a later reset ends the stopped single-commit pick once it clears unresolved index stages, so the next cherry-pick starts cleanly. Resolving the conflict and running a later commit ends the stopped single-commit pick the same way. In a multi-commit sequence the remaining commits are kept and the stopped commit is recorded as concluded; --continue does not re-commit a stop that was concluded outside the sequence, and instead applies the remaining commits.
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).
<A>..<B> is accepted as a commit range: it expands to the commits reachable
from B but not from A (oldest first, Git's rev-list --reverse A..B for
linear history) and is replayed as a sequence. A stop inside the range reports
the expanded commit, and --continue finalizes the resolved index as that
commit. A...B and other revision syntaxes remain unsupported.
Both rerere toggles are repeatable and the LAST one on the command line wins
(--rerere-autoupdate --no-rerere-autoupdate disables staging, and a trailing
positive flag re-enables it). They select the rerere staging policy for every pick, including picks expanded from a range: with
rerere.enabled set, a conflict whose resolution was recorded earlier is
replayed and (with autoupdate) staged automatically. Neither toggle can be
combined with --continue (LBR-CLI-002, naming both options).
On an unborn branch, --ff with a parentless (root) target fast-forwards the
branch to that commit: the branch ref is created at the target, HEAD stays a
symbolic ref to it, and the index/worktree are checked out without creating a
new commit. Non-fast-forward picks on an unborn branch are still unsupported.
On an unborn branch, --ff refuses while the index still has staged entries:
nothing is written (no sequencer state, index and worktree unchanged) and the
command fails with LBR-CONFLICT-001 plus a hint that the index must be empty
before fast-forwarding. cherry-pick - (only when - is the first revision argument) picks the
previous checkout target, like Git's @{-1}; other positions treat - as an
ordinary revision. -s/--signoff composes with it (cherry-pick -s -).
A picked commit stores Git's trailing-newline message form, so with the same
tree, parent, author/committer identity and dates (and no signing) a
cherry-pick commit's object id equals Git's. --ff only fast-forwards when HEAD
is the target's direct single parent; a target root commit (or any other
non-child) becomes an ordinary pick.
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).
-n, --no-commit
Apply the changes from the source commit to the index and working tree but do not create a new commit. This lets you inspect or combine the changes before committing manually with libra commit.
Multiple commits may be supplied; their changes accumulate in the index. Note that --no-commit cannot be combined with the conflict sequencer — a conflict during a multi-commit --no-commit pick is terminal (clean up with libra reset --hard/libra restore), since there are no intermediate commits to resume from.
# Stage changes from abc1234 without committing
libra cherry-pick -n abc1234
# Inspect staged changes, then commit manually
libra status
libra commit -m "cherry-picked and adjusted abc1234"
-x
Append (cherry picked from commit <hash>) to the new commit message. Without -x, Libra keeps the source commit message without adding the provenance line, matching Git's default behavior.
# Record the original commit hash in the new commit message
libra cherry-pick -x abc1234
-s, --signoff
Add a Signed-off-by: <name> <email> trailer (from the configured user.name/user.email) to the new commit message. When combined with -x, the (cherry picked from commit ...) line is emitted first and Signed-off-by last, matching Git's trailer ordering.
-e, --edit
Open an editor on the assembled commit message before committing. The editor is resolved from core.editor, then $VISUAL, then $EDITOR. In machine/JSON mode or without an interactive TTY, -e degrades to the assembled message without launching an editor (so it never blocks automation).
-m <n>, --mainline <n>
Cherry-pick a merge commit, using parent number <n> (1-based) as the diff base. Required for merge commits — a merge commit without -m is rejected. -m on a non-merge commit, or an out-of-range parent number, is also rejected (LBR-CLI-002).
# Cherry-pick a merge commit along its first parent
libra cherry-pick -m 1 <merge-commit>
--ff
When the picked commit is a single-parent direct child of HEAD and no commit-rewriting modifier is set, fast-forward HEAD to that commit without replaying or rewriting it (no hash drift).
-S, --gpg-sign
GPG-sign the cherry-picked commit using the libra vault signing key. Signing happens on explicit request regardless of the vault.signing config default. If the vault has no signing key available the pick fails rather than producing an unsigned commit.
--allow-empty
Cherry-pick a commit even if its own change set is empty (its tree equals its parent's). By default such commits are rejected (LBR-CLI-002).
--allow-empty-message
Allow the new commit to be created with an empty message. By default an empty message is rejected (LBR-CLI-002).
--keep-redundant-commits
Keep a commit that becomes redundant after being replayed (its resulting tree is identical to the current HEAD). By default an empty replay is a RESUMABLE stop (--empty=stop): it prints Git's The previous cherry-pick is now empty diagnostic, keeps the sequencer state (current_oid is the picked commit), and exits 1 with LBR-CONFLICT-001; --abort restores the original HEAD. Equivalent to --empty=keep. It conflicts with the control options --continue, --skip, --abort and --quit (clap rejects the pair with cannot be used with, LBR-CLI-002, before the command body runs).
--empty=<mode>
How to handle a pick whose change set becomes redundant against HEAD after replay. <mode> is stop (default — a resumable stop with the Git diagnostic, LBR-CONFLICT-001 and exit code 1), drop (skip the commit; HEAD does not advance and a dropping <sha> <subject> -- patch contents already upstream notice is printed), or keep (record the now-empty commit; same as --keep-redundant-commits). An invalid mode is a usage error (LBR-CLI-002, exit 129), validated before any commit (and before --continue/--skip/--abort/--quit).
--cleanup=<mode>
Clean up the replayed commit message. <mode> is strip/whitespace/verbatim/scissors/default. The picked body — and any -e edited buffer — is cleaned first, then the generated -x/Signed-off-by trailers are appended (so their separator is preserved). default and scissors fall back to whitespace when no editor opens (matching Git's "if the message is to be edited" clause). An unrecognized mode is a usage error (LBR-CLI-002, exit 129), validated before any commit (and before --continue/--skip/--abort/--quit). When omitted, the message is trim-only, as before.
-X <ours|theirs>, --strategy-option=<ours|theirs>
Resolve only overlapping three-way-apply hunks in favor of the selected side: ours is the current index/HEAD side and theirs is the commit being picked. Clean hunks from both sides are still applied. The option is repeatable and the last value wins; add/add and modify/delete conflicts select the requested whole side. The effective value is persisted for a resumed multi-commit sequence.
Conflict Sequencer
When a pick conflicts, resolve the affected files, stage them with libra add, then continue or cancel:
--continue
Resume the in-progress cherry-pick after resolving conflicts. The index must have no unresolved conflict stages, or --continue is refused (LBR-CONFLICT-001). Finalizes the conflicted commit and applies any remaining commits in the sequence.
--skip
Drop the current conflicted commit (restoring the worktree to the last successful tip) and continue with the rest of the sequence.
--abort
Cancel the in-progress cherry-pick and reset HEAD/worktree back to the state before the sequence began.
--quit
Forget the in-progress cherry-pick without changing the index or working tree (the conflict markers are left in place).
# A pick conflicts; resolve, stage, and continue:
libra cherry-pick abc1234 def5678
# ... edit conflicted files ...
libra add <resolved-files>
libra cherry-pick --continue
# Or drop just the conflicted commit:
libra cherry-pick --skip
# Or undo the whole sequence:
libra cherry-pick --abort
<commit>... (positional, required)
One or more commit references to cherry-pick. Each value can be a full SHA-1 hash, an abbreviated hash, a branch name, HEAD, or any ref that resolves to a commit. Commits are applied left-to-right.
# Single commit by hash
libra cherry-pick abc1234
# Multiple commits in order
libra cherry-pick abc1234 def5678 ghi9012
--json
Emit machine-readable JSON output instead of human-readable text. See Structured Output below.
--quiet
Suppress all human-readable output. Exit code still indicates success or failure.
Common Commands
# Cherry-pick a single commit onto the current branch
libra cherry-pick abc1234
# Cherry-pick multiple commits in sequence
libra cherry-pick abc1234 def5678
# Cherry-pick without committing, to edit or combine changes
libra cherry-pick -n abc1234
# Cherry-pick and record the original commit hash in the new message
libra cherry-pick -x abc1234
# Cherry-pick a merge commit along its first parent, signed off
libra cherry-pick -m 1 -s <merge-commit>
# Resume after resolving a conflict
libra add <resolved-files> && libra cherry-pick --continue
# Cherry-pick with JSON output for AI agents or scripts
libra cherry-pick --json abc1234
Human Output
When cherry-picking with auto-commit (default):
[def5678] cherry-picked from abc1234
When cherry-picking without auto-commit (-n):
Changes from abc1234 staged. Use 'libra commit' to finalize.
Structured Output (JSON examples)
{
"command": "cherry-pick",
"data": {
"picked": [
{
"source_commit": "abc1234abcdef1234567890abcdef1234567890ab",
"short_source": "abc1234",
"new_commit": "def5678abcdef1234567890abcdef1234567890ab",
"short_new": "def5678"
}
],
"no_commit": false
}
}
When --no-commit is used, new_commit and short_new are null:
{
"command": "cherry-pick",
"data": {
"picked": [
{
"source_commit": "abc1234abcdef1234567890abcdef1234567890ab",
"short_source": "abc1234",
"new_commit": null,
"short_new": null
}
],
"no_commit": true
}
}
Design Rationale (Why different from Git/jj)
Sequencer state lives in SQLite, not dotfiles
Git maintains .git/CHERRY_PICK_HEAD and sequencer state files. Libra persists the in-progress sequence in the unified SQLite sequence_state table, matching the repository's metadata-in-SQLite convention and the cross-operation sequencer mutex. The save is transactional, so state is never left half-applied and no loose dotfile can drift from refs. The AI-agent protocol is the same as Git's: detect the conflict code (LBR-CONFLICT-001), resolve, libra add, then --continue (or --skip/--abort/--quit).
Line-level conflict hunks
A divergent path is surfaced with line-level conflict markers, matching Git: a three-way merge (base = parent tree, ours = current index, theirs = picked tree) encloses only the diverging hunks between <<<<<<< HEAD / ======= / >>>>>>> <abbrev7> (<subject>), leaving lines that both sides share outside the markers. A delete/modify conflict (one side absent) or binary content falls back to a whole-file presentation, where a line-level merge would be meaningless. Under merge.conflictStyle=diff3, the ancestor label is parent of <abbrev7> (<subject>).
The Git-compatible merge.conflictStyle config is honored, same as libra merge: merge re-diffs the two postimages to expose common edges and longer common runs, diff3 adds the complete ancestor block, and zdiff3 keeps that ancestor block while trimming common postimage prefixes and suffixes. An unknown value is a hard error before index or working-tree writes whenever a divergent content merge needs the renderer. Marker lines follow uniformly CRLF input; otherwise they use LF. See the merge documentation.
Custom strategies remain explicit
-X ours/theirs is supported by Libra's built-in three-way apply and resolves only conflict regions. --rerere-autoupdate stages a replayed resolution, while --no-rerere-autoupdate leaves it unstaged; the last supplied flag wins and omitting both inherits rerere.autoUpdate. Rerere matches normalized hunk sides and only writes a clean three-way replay. The selected value is retained in the SQLite sequencer state so --continue preserves it. Both flags are no-ops while rerere is disabled. --strategy <name> remains explicitly rejected with LBR-UNSUPPORTED-001 (exit 128), because external/custom merge strategies are still out of scope.
Parameter Comparison: Libra vs Git vs jj
| Parameter | Git | jj | Libra |
|---|---|---|---|
| Positional commits | git cherry-pick <commit>... |
N/A (uses jj rebase) |
libra cherry-pick <commit>... |
| No-commit mode | --no-commit / -n |
N/A | --no-commit / -n (also multi-commit) |
| Record source | -x |
N/A | -x |
| Edit message | --edit / -e |
N/A | --edit / -e (degrades in machine mode) |
| Sign-off | --signoff / -s |
N/A | --signoff / -s |
| Mainline parent | --mainline <n> / -m <n> |
N/A | --mainline <n> / -m <n> |
| Fast-forward | --ff |
N/A | --ff |
| Continue after conflict | --continue |
N/A | --continue |
| Abort in-progress | --abort |
N/A | --abort |
| Skip current commit | --skip |
N/A | --skip |
| Quit sequencer | --quit |
N/A | --quit |
| GPG sign | --gpg-sign / -S |
N/A | --gpg-sign / -S (via libra vault) |
| Allow empty | --allow-empty |
N/A | --allow-empty |
| Allow empty message | --allow-empty-message |
N/A | --allow-empty-message |
| Keep redundant | --keep-redundant-commits |
N/A | --keep-redundant-commits |
| Cleanup mode | --cleanup=<mode> |
N/A | --cleanup=<mode> (strip/whitespace/verbatim/scissors/default; cleans the body/edited buffer, then appends trailers) |
| Strategy | --strategy <s> |
N/A | Rejected (LBR-UNSUPPORTED-001) |
| Strategy option | -X <option> |
N/A | -X ours/theirs (repeatable; last wins; conflict hunks only) |
| Empty mode | --empty=<mode> |
N/A | --empty=<mode> (stop/drop/keep) |
| JSON output | N/A | N/A | --json |
| Quiet mode | --quiet |
--quiet |
--quiet |
Note: jj does not have a direct cherry-pick equivalent. The closest operation is jj rebase -r <rev> -d <dest>, which moves or copies a commit to a new destination.
Error Handling
| Code | Condition | Hint |
|---|---|---|
LBR-REPO-001 |
Not inside a libra repository | Initialize with libra init or navigate to a repo |
LBR-REPO-003 |
No cherry-pick in progress for --continue/--skip/--abort/--quit, --continue on the wrong branch, or an interrupted --skip/--abort that has not finished (--continue refuses until it does) |
Switch to a branch / start a pick first / switch back to the sequence branch / re-run the interrupted --skip or --abort (or forget the sequence with --quit) |
LBR-REPO-003 |
--continue on a stop a later reset already concluded the stopped commit |
Drain the rest with libra cherry-pick --skip, or forget the sequence with --quit (keeps the reset result); --abort restores the pre-sequence state (discarding later tracked changes, including the reset target) |
LBR-REPO-002 |
The sequence row claims its stopped commit was concluded while no commits remain — a shape no writer produces | Nothing is changed: end the sequence with libra cherry-pick --abort or --quit |
LBR-CLI-003 |
Cannot resolve a commit reference | Use libra log to find valid commit references |
LBR-CLI-002 |
Merge commit without -m, invalid/out-of-range -m, an invalid --cleanup or --empty mode, empty commit without --allow-empty, redundant commit without --keep-redundant-commits/--empty=drop/--empty=keep, or empty message without --allow-empty-message |
Use the flag named in the hint |
LBR-UNSUPPORTED-001 |
An unsupported custom --strategy was passed, or an input of the pick sequence carries a 160000 gitlink (submodule) the pick would have to arbitrate |
Drop --strategy; for a gitlink, resolve the submodule pointer outside Libra or drop the entry from the commits involved — the refusal comes before the first index/worktree/state write |
LBR-CONFLICT-001 |
A three-way conflict that stops a commit-per-pick sequence | Resolve and libra add, then libra cherry-pick --continue (or --skip/--abort/--quit) |
LBR-CONFLICT-001 |
A new pick refused because the index already has unmerged entries (no sequence is started) | Resolve the listed paths and libra add them (or discard with libra reset --hard), then rerun the cherry-pick; --continue/--skip/--abort do not apply |
LBR-CONFLICT-001 |
A --no-commit pick stopped on conflicts (no sequence to continue) |
Resolve the paths, libra add (or libra rm) them and run libra commit, or discard the staged pick with libra reset --hard; --continue/--skip/--abort do not apply |
LBR-CONFLICT-001 |
A pick would overwrite an untracked working tree file (refused before that commit writes the index, worktree or refs) | Move or remove the named file. If nothing of the run was applied or staged yet, nothing was written: run the same command again. If earlier commits of a commit-per-pick sequence already landed, the sequence stops before this commit: run libra cherry-pick --continue (it re-attempts this commit), --skip or --abort. If earlier picks of a --no-commit run are staged, no sequence exists: pick the remaining commits again with -n, or discard everything with libra reset --hard |
LBR-CONFLICT-002 |
Another sequencer operation (merge, rebase or revert) started while a cherry-pick is in progress, or a new pick started over an in-progress sequence |
Finish or cancel the in-progress sequence first |
LBR-IO-001 |
Failed to load an object or cherry-pick state | Check repository integrity and retry |
LBR-IO-002 |
Failed to save object, index, or update branch ref/state | Check filesystem permissions and repository writability |
Cherry-picked revisions use the sidecar Change ID projection and typed
predecessor genealogy. Existing commit headers remain readable for import, but
new commits do not depend on or inject a change-id header.
Issue #477 notes
--continuedoes not re-commit a stop that was concluded outside the sequence- conflict markers label the picked side as the abbreviated commit and its subject