LibraLibra
LibraLibra
DocsBlogLibra
Getting Started
Architecture
Design
Commands
libra addlibra agentlibra alternateslibra applylibra archivelibra authlibra automationlibra bisectlibra blamelibra branchlibra bundlelibra cachelibra cat-filelibra check-attrlibra check-ignorelibra check-mailmaplibra checkoutlibra cherry-picklibra cleanlibra clonelibra cloudlibra code-controllibra codelibra commit-treelibra commitlibra completionslibra configlibra credentiallibra depslibra describelibra diff-fileslibra diff-indexlibra diff-treelibra difflibra dirtylibra fast-exportlibra fast-importlibra fetchlibra filelibra for-each-reflibra format-patchlibra fscklibra gclibra graphlibra greplibra hash-objectlibra hookslibra hydratelibra index-packlibra initlibra investigatelibra layerlibra lfslibra loglibra logfilelibra loginlibra logoutlibra ls-fileslibra ls-remotelibra ls-treelibra maintenancelibra medialibra merge-baselibra merge-filelibra mergelibra metadatalibra mvlibra noteslibra oplibra openlibra pack-objectslibra packagelibra prunelibra publishlibra pulllibra pushlibra read-treelibra rebaselibra refloglibra remotelibra repacklibra replacelibra rererelibra resetlibra restorelibra rev-listlibra rev-parselibra revertlibra reviewlibra revisionlibra rmlibra sandboxlibra servicelibra shortloglibra show-reflibra showlibra sparse-viewlibra stashlibra statslibra statuslibra switchlibra symbolic-reflibra taglibra update-indexlibra update-reflibra usagelibra verify-packlibra whoamilibra worktreelibra write-tree
API Reference
Policy
Commands

libra format-patch

Command reference for `libra format-patch`

Generate mbox-formatted email patch files from commits.

Synopsis

libra format-patch [OPTIONS] [revision-range]

Description

libra format-patch walks a revision range (A..B or a single commit treated as <commit>..HEAD), produces one patch file per non-merge commit (named with the --suffix, default .patch, unless --numbered-files is set, which uses bare sequence numbers), and formats each as an mbox message with RFC 2822 headers, a plain-text diffstat, and a unified diff. The output is compatible with git am.

Merge commits are skipped by default. When the revision range resolves to zero commits, the command exits with an error.

Options

FlagShortDescriptionDefault
[revision-range]A..B range or single commit; single commit means <commit>..HEADHEAD
--output-directory <DIR>-oWrite patch files into DIRcurrent directory
--stdoutPrint all patches to stdoutfalse
--numbered-nName files with a leading sequence number (0001-subject.patch)false
--start-number <N>Start numbering at N1
--subject-prefix <PREFIX>Use PREFIX instead of PATCH in the Subject: linePATCH
--cover-letterGenerate a cover-letter template (0000-cover-letter<suffix>, or 0 under --numbered-files)false
--threadAdd In-Reply-To and References headers (default on)true
--no-threadDisable threading headersfalse
--in-reply-to <MESSAGE_ID>Make the first mail a reply to the given Message-IDnone
--to <ADDRESS>Add a To: header (repeatable; multiple addresses fold like git). Placed after the MIME headers, on each patch and the cover letternone
--cc <ADDRESS>Add a Cc: header (repeatable; folds like git)none
--no-to / --no-ccSuppress the To: / Cc: headers (Libra has no format.to/format.cc config to reset)false
--from[=<IDENT>]Use <IDENT> in the From: header instead of the commit author (bare --from uses the committer's configured identity). When it differs from the author, the original author is preserved as an in-body From: line so git am can restore itauthor
--reroll-count <N>-vMark as version N (changes [PATCH] to [PATCH vN])none
--signoff-sAppend a Signed-off-by trailer to each commit messagefalse
--notes[=<REF>]Append each commit's notes after the --- line, before the diffstat. Bare --notes uses the default ref (refs/notes/commits); --notes=<ref> reads <ref>. Rendered as Notes: (default ref) or Notes (<ref>):, each line indented four spaces; commits without a note are emitted unchangedoff
--attachEmit each patch as a multipart/mixed MIME message: the log message + diffstat in a text/plain part, the diff in a text/x-patch part with Content-Disposition: attachment. Mutually exclusive with --inlineoff
--inlineLike --attach, but the patch part uses Content-Disposition: inlineoff
--base <COMMIT>Record a base-commit: trailer (and a prerequisite-patch-id: line for each non-merge commit between the base and the series, oldest-first) so git am --base can verify the series applies. The trailer rides on the last patch, or the cover letter under --cover-letter. The base must be an ancestor of the series (otherwise exit 128). --base=auto is not supported (exit 129). Patch-ids match git patch-id --stable for text diffs; binary-file prerequisites are not guaranteed to match Gitoff
--full-indexShow full object IDs in diff index header linesfalse
--no-statSuppress the diffstat summaryfalse
--keep-subjectKeep the original [PATCH] prefix in the commit subjectfalse
--suffix <SFX>Filename suffix for generated patches (e.g. .txt); ignored under --numbered-files.patch
--zero-commitUse an all-zero hash in each patch's From <hash> envelope linefalse
--signature <SIGNATURE>Text placed after the -- line of each patch and the cover letterlibra version
--no-signatureOmit the -- /signature footer entirelyfalse
--signature-file <FILE>Read the signature footer text from a file (mutually exclusive with --signature)
--encode-email-headers / --no-encode-email-headersRFC 2047 Q-encode From/Subject header values that contain non-ASCII charactersoff
--numbered-filesName output files by a bare sequence number (suffix not applied)false

Examples

Basic range

# Generate patches for the last three commits
libra format-patch HEAD~3..HEAD

# Numbered patches in a directory
libra format-patch -n -o patches/ main..feature

# With cover letter and threading
libra format-patch --cover-letter --thread origin/main..

# Version 2, replying to a previous thread
libra format-patch -v 2 --in-reply-to '<msgid@example>' origin/main..

# Pipe to an external tool
libra format-patch --stdout origin/main.. | git am

# Record the base the series applies to (for `git am --base`)
libra format-patch --base=origin/main --stdout origin/main..HEAD

Output Format

Each patch file is an mbox message:

From <commit-oid> <unix-mbox-date>
From: Author Name <email>
Date: <RFC 2822 date>
Subject: [PATCH n/m] commit subject
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

commit message body
---
diffstat summary
unified diff
--
<libra-version>

The -- footer defaults to the libra version; --signature <text> replaces it with custom text, --signature-file <file> reads the footer text from a file, and --no-signature omits the footer entirely. --encode-email-headers RFC 2047 Q-encodes From/Subject header values that contain non-ASCII characters. It is off by default in Libra (which has no format.encodeEmailHeaders config knob); Git derives its default from that config, which is itself off unless set.

With --json or --machine, data.patches lists every generated output. When --cover-letter is set, the list includes the cover letter as record number 0 before the commit patch records. Its filename is 0000-cover-letter with the configured suffix (default .patch), or just 0 under --numbered-files.

Error Handling

ScenarioStableErrorCode
Not in a Libra repositoryLBR-REPO-001
Unknown revision or empty rangeLBR-CLI-003
--base is not an ancestor of the seriesLBR-CLI-003 (exit 128)
--base=auto (unsupported)LBR-CLI-002 (exit 129)
Output file write failureLBR-IO-002
Output directory creation failureLBR-IO-002

libra for-each-ref

Command reference for `libra for-each-ref`

libra fsck

Command reference for `libra fsck`

On this page

SynopsisDescriptionOptionsExamplesBasic rangeOutput FormatError Handling