<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<article lang="en" id="git-rev-parse(1)">
<articleinfo>
    <title>git-rev-parse(1)</title>
        <indexterm>
                <primary>git-rev-parse(1)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>git-rev-parse - Pick out and massage parameters</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<simpara><emphasis>git rev-parse</emphasis> [ --option ] &lt;args&gt;&#8230;</simpara>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>Many git porcelainish commands take mixture of flags
(i.e. parameters that begin with a dash <emphasis>-</emphasis>) and parameters
meant for the underlying <emphasis>git-rev-list</emphasis> command they use internally
and flags and parameters for the other commands they use
downstream of <emphasis>git-rev-list</emphasis>.  This command is used to
distinguish between them.</simpara>
</simplesect>
<simplesect id="_options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
--parseopt
</term>
<listitem>
<simpara>
        Use <emphasis>git-rev-parse</emphasis> in option parsing mode (see PARSEOPT section below).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--keep-dash-dash
</term>
<listitem>
<simpara>
        Only meaningful in <literal>--parseopt</literal> mode. Tells the option parser to echo
        out the first <literal>--</literal> met instead of skipping it.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--revs-only
</term>
<listitem>
<simpara>
        Do not output flags and parameters not meant for
        <emphasis>git-rev-list</emphasis> command.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-revs
</term>
<listitem>
<simpara>
        Do not output flags and parameters meant for
        <emphasis>git-rev-list</emphasis> command.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--flags
</term>
<listitem>
<simpara>
        Do not output non-flag parameters.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-flags
</term>
<listitem>
<simpara>
        Do not output flag parameters.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--default &lt;arg&gt;
</term>
<listitem>
<simpara>
        If there is no parameter given by the user, use <literal>&lt;arg&gt;</literal>
        instead.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--verify
</term>
<listitem>
<simpara>
        The parameter given must be usable as a single, valid
        object name.  Otherwise barf and abort.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-q
</term>
<term>
--quiet
</term>
<listitem>
<simpara>
        Only meaningful in <literal>--verify</literal> mode. Do not output an error
        message if the first argument is not a valid object name;
        instead exit with non-zero status silently.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--sq
</term>
<listitem>
<simpara>
        Usually the output is made one line per flag and
        parameter.  This option makes output a single line,
        properly quoted for consumption by shell.  Useful when
        you expect your parameter to contain whitespaces and
        newlines (e.g. when using pickaxe <literal>-S</literal> with
        <emphasis>git-diff-\*</emphasis>).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--not
</term>
<listitem>
<simpara>
        When showing object names, prefix them with <emphasis>&#94;</emphasis> and
        strip <emphasis>&#94;</emphasis> prefix from the object names that already have
        one.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--symbolic
</term>
<listitem>
<simpara>
        Usually the object names are output in SHA1 form (with
        possible <emphasis>&#94;</emphasis> prefix); this option makes them output in a
        form as close to the original input as possible.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--symbolic-full-name
</term>
<listitem>
<simpara>
        This is similar to --symbolic, but it omits input that
        are not refs (i.e. branch or tag names; or more
        explicitly disambiguating "heads/master" form, when you
        want to name the "master" branch when there is an
        unfortunately named tag "master"), and show them as full
        refnames (e.g. "refs/heads/master").
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--all
</term>
<listitem>
<simpara>
        Show all refs found in <literal>$GIT_DIR/refs</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--branches
</term>
<listitem>
<simpara>
        Show branch refs found in <literal>$GIT_DIR/refs/heads</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--tags
</term>
<listitem>
<simpara>
        Show tag refs found in <literal>$GIT_DIR/refs/tags</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--remotes
</term>
<listitem>
<simpara>
        Show tag refs found in <literal>$GIT_DIR/refs/remotes</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--show-prefix
</term>
<listitem>
<simpara>
        When the command is invoked from a subdirectory, show the
        path of the current directory relative to the top-level
        directory.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--show-cdup
</term>
<listitem>
<simpara>
        When the command is invoked from a subdirectory, show the
        path of the top-level directory relative to the current
        directory (typically a sequence of "../", or an empty string).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--git-dir
</term>
<listitem>
<simpara>
        Show <literal>$GIT_DIR</literal> if defined else show the path to the .git directory.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--is-inside-git-dir
</term>
<listitem>
<simpara>
        When the current working directory is below the repository
        directory print "true", otherwise "false".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--is-inside-work-tree
</term>
<listitem>
<simpara>
        When the current working directory is inside the work tree of the
        repository print "true", otherwise "false".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--is-bare-repository
</term>
<listitem>
<simpara>
        When the repository is bare print "true", otherwise "false".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--short
</term>
<term>
--short=number
</term>
<listitem>
<simpara>
        Instead of outputting the full SHA1 values of object names try to
        abbreviate them to a shorter unique name. When no length is specified
        7 is used. The minimum length is 4.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--since=datestring
</term>
<term>
--after=datestring
</term>
<listitem>
<simpara>
        Parse the date string, and output the corresponding
        --max-age= parameter for <emphasis>git-rev-list</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--until=datestring
</term>
<term>
--before=datestring
</term>
<listitem>
<simpara>
        Parse the date string, and output the corresponding
        --min-age= parameter for <emphasis>git-rev-list</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
&lt;args&gt;&#8230;
</term>
<listitem>
<simpara>
        Flags and parameters to be parsed.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_specifying_revisions">
<title>SPECIFYING REVISIONS</title>
<simpara>A revision parameter typically, but not necessarily, names a
commit object.  They use what is called an <emphasis>extended SHA1</emphasis>
syntax.  Here are various ways to spell object names.  The
ones listed near the end of this list are to name trees and
blobs contained in a commit.</simpara>
<itemizedlist>
<listitem>
<simpara>
The full SHA1 object name (40-byte hexadecimal string), or
  a substring of such that is unique within the repository.
  E.g. dae86e1950b1277e545cee180551750029cfe735 and dae86e both
  name the same commit object if there are no other object in
  your repository whose object name starts with dae86e.
</simpara>
</listitem>
<listitem>
<simpara>
An output from <emphasis>git-describe</emphasis>; i.e. a closest tag, optionally
  followed by a dash and a number of commits, followed by a dash, a
  <literal>g</literal>, and an abbreviated object name.
</simpara>
</listitem>
<listitem>
<simpara>
A symbolic ref name.  E.g. <emphasis>master</emphasis> typically means the commit
  object referenced by $GIT_DIR/refs/heads/master.  If you
  happen to have both heads/master and tags/master, you can
  explicitly say <emphasis>heads/master</emphasis> to tell git which one you mean.
  When ambiguous, a <literal>&lt;name&gt;</literal> is disambiguated by taking the
  first match in the following rules:
</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
if <literal>$GIT_DIR/&lt;name&gt;</literal> exists, that is what you mean (this is usually
    useful only for <literal>HEAD</literal>, <literal>FETCH_HEAD</literal>, <literal>ORIG_HEAD</literal> and <literal>MERGE_HEAD</literal>);
</simpara>
</listitem>
<listitem>
<simpara>
otherwise, <literal>$GIT_DIR/refs/&lt;name&gt;</literal> if exists;
</simpara>
</listitem>
<listitem>
<simpara>
otherwise, <literal>$GIT_DIR/refs/tags/&lt;name&gt;</literal> if exists;
</simpara>
</listitem>
<listitem>
<simpara>
otherwise, <literal>$GIT_DIR/refs/heads/&lt;name&gt;</literal> if exists;
</simpara>
</listitem>
<listitem>
<simpara>
otherwise, <literal>$GIT_DIR/refs/remotes/&lt;name&gt;</literal> if exists;
</simpara>
</listitem>
<listitem>
<simpara>
otherwise, <literal>$GIT_DIR/refs/remotes/&lt;name&gt;/HEAD</literal> if exists.
</simpara>
<simpara>HEAD names the commit your changes in the working tree is based on.
FETCH_HEAD records the branch you fetched from a remote repository
with your last <emphasis>git-fetch</emphasis> invocation.
ORIG_HEAD is created by commands that moves your HEAD in a drastic
way, to record the position of the HEAD before their operation, so that
you can change the tip of the branch back to the state before you ran
them easily.
MERGE_HEAD records the commit(s) you are merging into your branch
when you run <emphasis>git-merge</emphasis>.</simpara>
</listitem>
</orderedlist>
</listitem>
<listitem>
<simpara>
A ref followed by the suffix <emphasis>@</emphasis> with a date specification
  enclosed in a brace
  pair (e.g. <emphasis>{yesterday}</emphasis>, <emphasis>{1 month 2 weeks 3 days 1 hour 1
  second ago}</emphasis> or <emphasis>{1979-02-26 18:30:00}</emphasis>) to specify the value
  of the ref at a prior point in time.  This suffix may only be
  used immediately following a ref name and the ref must have an
  existing log ($GIT_DIR/logs/&lt;ref&gt;). Note that this looks up the state
  of your <emphasis role="strong">local</emphasis> ref at a given time; e.g., what was in your local
  <literal>master</literal> branch last week. If you want to look at commits made during
  certain times, see <literal>--since</literal> and <literal>--until</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
A ref followed by the suffix <emphasis>@</emphasis> with an ordinal specification
  enclosed in a brace pair (e.g. <emphasis>{1}</emphasis>, <emphasis>{15}</emphasis>) to specify
  the n-th prior value of that ref.  For example <emphasis>master@{1}</emphasis>
  is the immediate prior value of <emphasis>master</emphasis> while <emphasis>master@{5}</emphasis>
  is the 5th prior value of <emphasis>master</emphasis>. This suffix may only be used
  immediately following a ref name and the ref must have an existing
  log ($GIT_DIR/logs/&lt;ref&gt;).
</simpara>
</listitem>
<listitem>
<simpara>
You can use the <emphasis>@</emphasis> construct with an empty ref part to get at a
  reflog of the current branch. For example, if you are on the
  branch <emphasis>blabla</emphasis>, then <emphasis>@{1}</emphasis> means the same as <emphasis>blabla@{1}</emphasis>.
</simpara>
</listitem>
<listitem>
<simpara>
The special construct <emphasis>@{-&lt;n&gt;}</emphasis> means the &lt;n&gt;th branch checked out
  before the current one.
</simpara>
</listitem>
<listitem>
<simpara>
A suffix <emphasis>&#94;</emphasis> to a revision parameter means the first parent of
  that commit object.  <emphasis>&#94;&lt;n&gt;</emphasis> means the &lt;n&gt;th parent (i.e.
  <emphasis>rev&#94;</emphasis>
  is equivalent to <emphasis>rev&#94;1</emphasis>).  As a special rule,
  <emphasis>rev&#94;0</emphasis> means the commit itself and is used when <emphasis>rev</emphasis> is the
  object name of a tag object that refers to a commit object.
</simpara>
</listitem>
<listitem>
<simpara>
A suffix <emphasis>&#126;&lt;n&gt;</emphasis> to a revision parameter means the commit
  object that is the &lt;n&gt;th generation grand-parent of the named
  commit object, following only the first parent.  I.e. rev~3 is
  equivalent to rev&#94;&#94;&#94; which is equivalent to
  rev&#94;1&#94;1&#94;1.  See below for a illustration of
  the usage of this form.
</simpara>
</listitem>
<listitem>
<simpara>
A suffix <emphasis>&#94;</emphasis> followed by an object type name enclosed in
  brace pair (e.g. <literal>v0.99.8&#94;{commit}</literal>) means the object
  could be a tag, and dereference the tag recursively until an
  object of that type is found or the object cannot be
  dereferenced anymore (in which case, barf).  <literal>rev&#94;0</literal>
  introduced earlier is a short-hand for <literal>rev&#94;{commit}</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
A suffix <emphasis>&#94;</emphasis> followed by an empty brace pair
  (e.g. <literal>v0.99.8&#94;{}</literal>) means the object could be a tag,
  and dereference the tag recursively until a non-tag object is
  found.
</simpara>
</listitem>
<listitem>
<simpara>
A colon, followed by a slash, followed by a text: this names
  a commit whose commit message starts with the specified text.
  This name returns the youngest matching commit which is
  reachable from any ref.  If the commit message starts with a
  <emphasis>!</emphasis>, you have to repeat that;  the special sequence <emphasis>:/!</emphasis>,
  followed by something else than <emphasis>!</emphasis> is reserved for now.
</simpara>
</listitem>
<listitem>
<simpara>
A suffix <emphasis>:</emphasis> followed by a path; this names the blob or tree
  at the given path in the tree-ish object named by the part
  before the colon.
</simpara>
</listitem>
<listitem>
<simpara>
A colon, optionally followed by a stage number (0 to 3) and a
  colon, followed by a path; this names a blob object in the
  index at the given path.  Missing stage number (and the colon
  that follows it) names a stage 0 entry. During a merge, stage
  1 is the common ancestor, stage 2 is the target branch&#8217;s version
  (typically the current branch), and stage 3 is the version from
  the branch being merged.
</simpara>
</listitem>
</itemizedlist>
<simpara>Here is an illustration, by Jon Loeliger.  Both commit nodes B
and C are parents of commit node A.  Parent commits are ordered
left-to-right.</simpara>
<literallayout class="monospaced">G   H   I   J
 \ /     \ /
  D   E   F
   \  |  / \
    \ | /   |
     \|/    |
      B     C
       \   /
        \ /
         A</literallayout>
<literallayout class="monospaced">A =      = A^0
B = A^   = A^1     = A~1
C = A^2  = A^2
D = A^^  = A^1^1   = A~2
E = B^2  = A^^2
F = B^3  = A^^3
G = A^^^ = A^1^1^1 = A~3
H = D^2  = B^^2    = A^^^2  = A~2^2
I = F^   = B^3^    = A^^3^
J = F^2  = B^3^2   = A^^3^2</literallayout>
</simplesect>
<simplesect id="_specifying_ranges">
<title>SPECIFYING RANGES</title>
<simpara>History traversing commands such as <emphasis>git-log</emphasis> operate on a set
of commits, not just a single commit.  To these commands,
specifying a single revision with the notation described in the
previous section means the set of commits reachable from that
commit, following the commit ancestry chain.</simpara>
<simpara>To exclude commits reachable from a commit, a prefix <literal>&#94;</literal>
notation is used.  E.g. "<literal>&#94;r1 r2</literal>" means commits reachable
from <literal>r2</literal> but exclude the ones reachable from <literal>r1</literal>.</simpara>
<simpara>This set operation appears so often that there is a shorthand
for it.  When you have two commits <literal>r1</literal> and <literal>r2</literal> (named according
to the syntax explained in SPECIFYING REVISIONS above), you can ask
for commits that are reachable from r2 excluding those that are reachable
from r1 by "<literal>&#94;r1 r2</literal>" and it can be written as "<literal>r1..r2</literal>".</simpara>
<simpara>A similar notation "<literal>r1...r2</literal>" is called symmetric difference
of <literal>r1</literal> and <literal>r2</literal> and is defined as
"<literal>r1 r2 --not $(git merge-base --all r1 r2)</literal>".
It is the set of commits that are reachable from either one of
<literal>r1</literal> or <literal>r2</literal> but not from both.</simpara>
<simpara>Two other shorthands for naming a set that is formed by a commit
and its parent commits exist.  The <literal>r1&#94;@</literal> notation means all
parents of <literal>r1</literal>.  <literal>r1&#94;!</literal> includes commit <literal>r1</literal> but excludes
all of its parents.</simpara>
<simpara>Here are a handful of examples:</simpara>
<literallayout class="monospaced">D                G H D
D F              G H I J D F
^G D             H D
^D B             E I J F B
B...C            G H D E B C
^D B C           E I J F B C
C^@              I J F
F^! D            G H D F</literallayout>
</simplesect>
<simplesect id="_parseopt">
<title>PARSEOPT</title>
<simpara>In <literal>--parseopt</literal> mode, <emphasis>git-rev-parse</emphasis> helps massaging options to bring to shell
scripts the same facilities C builtins have. It works as an option normalizer
(e.g. splits single switches aggregate values), a bit like <literal>getopt(1)</literal> does.</simpara>
<simpara>It takes on the standard input the specification of the options to parse and
understand, and echoes on the standard output a line suitable for <literal>sh(1)</literal> <literal>eval</literal>
to replace the arguments with normalized ones.  In case of error, it outputs
usage on the standard error stream, and exits with code 129.</simpara>
<simplesect id="_input_format">
<title>Input Format</title>
<simpara><emphasis>git-rev-parse --parseopt</emphasis> input format is fully text based. It has two parts,
separated by a line that contains only <literal>--</literal>. The lines before the separator
(should be more than one) are used for the usage.
The lines after the separator describe the options.</simpara>
<simpara>Each line of options has this format:</simpara>
<literallayout>&lt;opt_spec&gt;&lt;flags&gt;* SP+ help LF</literallayout>
<variablelist>
<varlistentry>
<term>
<literal>&lt;opt_spec&gt;</literal>
</term>
<listitem>
<simpara>
        its format is the short option character, then the long option name
        separated by a comma. Both parts are not required, though at least one
        is necessary. <literal>h,help</literal>, <literal>dry-run</literal> and <literal>f</literal> are all three correct
        <literal>&lt;opt_spec&gt;</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>&lt;flags&gt;</literal>
</term>
<listitem>
<simpara>
        <literal>&lt;flags&gt;</literal> are of <literal>*</literal>, <literal>=</literal>, <literal>?</literal> or <literal>!</literal>.
</simpara>
<itemizedlist>
<listitem>
<simpara>
Use <literal>=</literal> if the option takes an argument.
</simpara>
</listitem>
<listitem>
<simpara>
Use <literal>?</literal> to mean that the option is optional (though its use is discouraged).
</simpara>
</listitem>
<listitem>
<simpara>
Use <literal>*</literal> to mean that this option should not be listed in the usage
          generated for the <literal>-h</literal> argument. It&#8217;s shown for <literal>--help-all</literal> as
          documented in <xref linkend="gitcli(7)"/>.
</simpara>
</listitem>
<listitem>
<simpara>
Use <literal>!</literal> to not make the corresponding negated long option available.
</simpara>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
</variablelist>
<simpara>The remainder of the line, after stripping the spaces, is used
as the help associated to the option.</simpara>
<simpara>Blank lines are ignored, and lines that don&#8217;t match this specification are used
as option group headers (start the line with a space to create such
lines on purpose).</simpara>
</simplesect>
<simplesect id="_example">
<title>Example</title>
<literallayout>OPTS_SPEC="\
some-command [options] &lt;args&gt;...

some-command does foo and bar!
--
h,help    show the help

foo       some nifty option --foo
bar=      some cool option --bar with an argument

  An option group Header
C?        option C with an optional argument"

eval `echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?`</literallayout>
</simplesect>
</simplesect>
<simplesect id="_examples">
<title>EXAMPLES</title>
<itemizedlist>
<listitem>
<simpara>
Print the object name of the current commit:
</simpara>
<literallayout>$ git rev-parse --verify HEAD</literallayout>
</listitem>
<listitem>
<simpara>
Print the commit object name from the revision in the $REV shell variable:
</simpara>
<literallayout>$ git rev-parse --verify $REV</literallayout>
<simpara>This will error out if $REV is empty or not a valid revision.</simpara>
</listitem>
<listitem>
<simpara>
Same as above:
</simpara>
<literallayout>$ git rev-parse --default master --verify $REV</literallayout>
<simpara>but if $REV is empty, the commit object name from master will be printed.</simpara>
</listitem>
</itemizedlist>
</simplesect>
<simplesect id="_author">
<title>Author</title>
<simpara>Written by Linus Torvalds &lt;<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>&gt; .
Junio C Hamano &lt;<ulink url="mailto:gitster@pobox.com">gitster@pobox.com</ulink>&gt; and Pierre Habouzit &lt;<ulink url="mailto:madcoder@debian.org">madcoder@debian.org</ulink>&gt;</simpara>
</simplesect>
<simplesect id="_documentation">
<title>Documentation</title>
<simpara>Documentation by Junio C Hamano and the git-list &lt;<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>&gt;.</simpara>
</simplesect>
<simplesect id="_git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
</simplesect>
</article>
