libra rev-parse
Command reference for `libra rev-parse`
Parse revision names and print normalized object IDs, symbolic refs, or repository paths.
Synopsis
libra rev-parse [OPTIONS] [SPEC]...
Description
libra rev-parse resolves a revision-like input into one of three forms:
- the full object ID (default)
- a short object ID with
--short - a symbolic branch name with
--abbrev-ref
It also supports --show-toplevel to print the absolute repository root for a working tree. When no <SPEC> is provided, the command defaults to HEAD; multiple <SPEC> arguments are each resolved on their own line. The output-filter flags (--flags/--no-flags/--revs-only/--no-revs) instead classify each argument as a flag, revision, or path and print a filtered subset.
The shared strict object-spec parser supports @ as HEAD, full tag refs,
^N/~N, ^{commit|tree|blob|tag|object} and recursive ^{} peeling,
numeric reflog selectors (main@{1}, HEAD@{0}, or @{1} for the current
branch), and <tree-ish>:<path>. It consumes the entire spec, so malformed
suffixes cannot silently degrade to a different object. Reflog date selectors,
@{-N}, @{upstream}/@{push}, and relative .//../ tree paths remain
unsupported and fail explicitly.
Index-path specs resolve the current worktree index: :<path> reads the
stage-0 entry, :<n>:<path> (n = 0–3) reads that merge stage (:0:p ≡ :p),
and a leading ./ or ../ resolves relative to the current directory; every
other path is repository-relative. A path absent from the index, a path whose
requested stage is missing while another stage exists, and a .//../ path
escaping the worktree all fail with LBR-CLI-003 (exit 129).
Message-search specs find a commit by its message body (everything after the
blank line that ends the commit header): :/<regex> starts from HEAD plus
every local branch, remote-tracking branch, and tag; <rev>^{/<regex>} starts
from <rev>. Both walk ancestors newest-first by committer timestamp and
return the first match. A leading !- negates the match, !! keeps a literal
leading !, and any other leading ! is an error; an invalid regex, an
oversized pattern, or no match is LBR-CLI-003 (exit 129). Patterns use the
Rust regex crate — a linear-time engine without backreferences or
lookaround — so some POSIX-ERE-only patterns do not compile; matching is
case-sensitive and only commit objects are read during the walk.
AUTO_MERGE is the sole pseudo-ref accepted by this command: during a
non-squash merge paused on conflicts, it resolves to the automatic result
tree, including conflict markers. It disappears after merge --continue,
--abort, or --quit; it is unavailable for clean and squash merges. The
six historical pseudo-refs (ORIG_HEAD, MERGE_HEAD, CHERRY_PICK_HEAD,
REVERT_HEAD, REBASE_HEAD, and FETCH_HEAD) remain rejected as revisions.
--show-ref-storage-format
Print the repository's ref storage backend. Libra stores refs in SQLite, so this
always prints sqlite (Git's files/reftable backends are not implemented —
see COMPATIBILITY.md, intentionally-different). --json returns
{"ref_storage_format": "sqlite"}.
libra rev-parse --show-ref-storage-format
Options
A Git describe name (<ref>-<count>-g<hex>) also resolves: after the tag,
local-branch and remote-branch literal lookups miss, the trailing object id names
the commit (v1-2-gabc1234). An existing ref with exactly that name still wins.
The suffix is resolved with Git's GET_OID_COMMIT rules: an abbreviated id must
be unambiguous unless exactly one candidate is a commit (that commit wins), a
full-length id must exist, and a non-hex or shorter-than-4-character id fails with
LBR-CLI-003 (no ambiguity listing is printed). An annotated tag object named by the suffix resolves to that tag object itself
(unpeeled), and blob and tree suffixes resolve to those objects — the root
namespace accepts every object type, like Git. The tags/ namespace resolves a
describe suffix after its own literal tag lookup and the complete-name lookups of
local and remote-tracking branches, so a real ref with that exact name always wins.
The same order applies inside the heads/ and remotes/ namespaces (literal
branch, then the complete-name lookups in the other namespaces, then the describe
suffix). The refs/-qualified forms (refs/tags/, refs/heads/,
refs/remotes/) follow the same order.
| Flag | Description |
|---|---|
--verify |
Assert that <SPEC> resolves to exactly one object; print it, or exit 128 on failure (silent exit 1 under the global --quiet / -q). |
--show-object-format[=<mode>] |
Print the repository's object format (sha1, sha256, or Libra's blake3). storage (the default), input, and output all report core.objectformat; compat prints an empty line because Libra has no compatibility hash. Other modes are LBR-CLI-002. Mutually exclusive with a SPEC. |
--short[=<n>] |
Print a non-ambiguous abbreviated object ID: start at <n> (default 7, minimum 4) and lengthen digit by digit until no OTHER object shares the prefix. A full-length object ID of the repository's hash kind is accepted even when the object is absent (Git abbreviates it anyway); --verify --short keeps that behaviour, while --verify without --short still requires the object to exist. |
--sq |
Shell-quote the resolved object name (single-quoted) for safe shell consumption. Only affects the resolved-revision output, not query modes like --show-toplevel. |
--abbrev-ref |
Print the symbolic branch name instead of a commit hash. |
--symbolic-full-name |
Resolve the spec to its full ref name (refs/heads/<branch>, refs/tags/<tag>, refs/remotes/<remote>/<branch>, or HEAD when detached). A valid object that is not a ref prints nothing (exit 0); an unresolvable name fails with exit 128. |
--symbolic |
Print the spec in symbolic form, as close to the original input as possible: a resolvable ref, revision expression, or object id is echoed verbatim (e.g. main stays main, not refs/heads/main). An unresolvable name fails with exit 128. Mutually exclusive with --symbolic-full-name/--short/--abbrev-ref. |
--flags |
Output-filter mode: classify each <SPEC> arg and print only flags (args beginning with -, before any --) and resolved revisions, dropping non-flag paths. |
--no-flags |
Output-filter mode: drop flag args, keeping resolved revisions and non-flag paths. |
--revs-only |
Output-filter mode: print only the args that resolve to revisions (as object names), dropping flags and non-revision paths. |
--no-revs |
Output-filter mode: drop revision args, keeping flags and non-revision paths. |
--show-toplevel |
Print the absolute path to the top-level working tree. |
--is-inside-git-dir |
Print true when the current directory is inside the .libra directory (Libra's $GIT_DIR equivalent), false otherwise. |
--is-shallow-repository |
Print true when .libra/shallow contains at least one shallow boundary, false otherwise. |
--git-dir |
Print the path to the .libra directory (Libra's $GIT_DIR). In Libra this is always absolute. |
--absolute-git-dir |
Like --git-dir, but always the canonicalized absolute path. (In Libra --git-dir is already absolute, so the two coincide.) |
<SPEC> |
Object/revision spec to resolve. Supports typed peel, numeric reflog selectors, REV:path, index paths (:<path>, :<n>:<path>), and commit-message search (:/<regex>, <rev>^{/<regex>}); defaults to HEAD when omitted. |
Common Commands
libra rev-parse
libra rev-parse HEAD~1
libra rev-parse 'HEAD^{tree}'
libra rev-parse 'HEAD:src/main.rs'
libra rev-parse :src/main.rs
libra rev-parse :2:src/main.rs
libra rev-parse ':/fix: crash'
libra rev-parse 'HEAD^{/fix}'
libra rev-parse 'main@{1}'
libra rev-parse --short HEAD
libra rev-parse --abbrev-ref HEAD
libra rev-parse --show-toplevel
libra rev-parse --is-inside-git-dir
libra rev-parse --is-shallow-repository
libra rev-parse --absolute-git-dir
libra --json rev-parse --short HEAD
Human Output
Default output is a single line containing the resolved value.
abc1234def5678901234567890abcdef12345678
With --short:
abc1234
With --abbrev-ref:
main
With --show-toplevel:
/home/alice/project
Structured Output
{
"ok": true,
"command": "rev-parse",
"data": {
"mode": "short",
"input": "HEAD",
"value": "abc1234"
}
}
mode is one of resolve, short, abbrev_ref, symbolic_full_name, symbolic, show_toplevel, show_prefix, show_cdup, is_inside_work_tree, is_inside_git_dir, is_bare_repository, is_shallow_repository, git_dir, or absolute_git_dir.
With a single <SPEC>, data is one such object (the shape above). With multiple <SPEC> arguments, data is a JSON array of those objects, one per spec, in order. In an output-filter mode (--flags/--no-flags/--revs-only/--no-revs), data is a JSON array of strings — the filtered tokens (resolved object names for revisions, verbatim for kept flags/paths).
Parameter Comparison: Libra vs Git vs jj
| Feature | Libra | Git | jj |
|---|---|---|---|
| Resolve full object ID | rev-parse <spec> |
git rev-parse <spec> |
jj log -r <rev> --no-graph -T commit_id |
| Typed/recursive peel | ^{commit/tree/blob/tag/object} / ^{} |
same | N/A |
| Tree path | REV:path |
same | jj file show -r REV path |
| Index path | :<path> / :<n>:<path> |
same | N/A |
| Message search | :/<regex>, <rev>^{/<regex>} |
same (POSIX ERE) | N/A |
| Reflog selector | numeric ref@{N} |
numeric/date/upstream/push/checkout forms | N/A |
| Abbreviated object ID | --short |
--short |
jj log -r <rev> -T change_id.short() |
| Symbolic branch name | --abbrev-ref |
--abbrev-ref |
N/A |
| Full ref name | --symbolic-full-name |
--symbolic-full-name |
N/A |
| Symbolic (verbatim) name | --symbolic |
--symbolic |
N/A |
| Output filters | --flags/--no-flags/--revs-only/--no-revs |
same | N/A |
| Shell-quoted output | --sq |
--sq |
N/A |
| Work tree root | --show-toplevel |
--show-toplevel |
jj root |
| JSON output | --json |
No | No |
A -- separator splits revisions from paths in every mode (rev-parse <rev> -- <path>): arguments after -- are paths, never revisions, and the -- is echoed where path output applies. The single-revision modes --verify and --short print only the one resolved object (never the paths).
A short object name that matches multiple distinct objects fails with error: short object ID <p> is ambiguous and a The candidates are: hint listing one <abbrev> <type> line per candidate (sorted by full object id), exit 129 (LBR-CLI-003; Git exits 128). With --json the error envelope's details.candidates carries each candidate's full oid, type, and shortest unique abbrev. Duplicate hits for the same object (a loose object that also exists in one or more packs) are merged first and do not count as ambiguity.
Intentional divergence from Git: combining
--verifyor--shortwith any output-filter flag (--flags/--no-flags/--revs-only/--no-revs) is rejected with a usage error (LBR-CLI-002, exit 129). Git's behavior for that combination is ill-defined, so Libra refuses it rather than guessing.
Error Handling
| Scenario | StableErrorCode | Exit |
|---|---|---|
| Invalid target ref | LBR-CLI-003 |
129 |
| Ambiguous short object name | LBR-CLI-003 |
129 |
--verify/--short combined with an output-filter flag |
LBR-CLI-002 |
129 |
| Invalid work tree state | LBR-REPO-003 |
128 |
| Failed to read repository metadata | LBR-IO-001 |
128 |
| Corrupt stored refs/config | LBR-REPO-002 |
128 |