1GIT-REV-PARSE(1)                  Git Manual                  GIT-REV-PARSE(1)
2
3
4

NAME

6       git-rev-parse - Pick out and massage parameters
7

SYNOPSIS

9       git rev-parse [ --option ] <args>...
10

DESCRIPTION

12       Many git porcelainish commands take mixture of flags (i.e. parameters
13       that begin with a dash -) and parameters meant for the underlying git
14       rev-list command they use internally and flags and parameters for the
15       other commands they use downstream of git rev-list. This command is
16       used to distinguish between them.
17

OPTIONS

19       --parseopt
20           Use git rev-parse in option parsing mode (see PARSEOPT section
21           below).
22
23       --keep-dashdash
24           Only meaningful in --parseopt mode. Tells the option parser to echo
25           out the first -- met instead of skipping it.
26
27       --stop-at-non-option
28           Only meaningful in --parseopt mode. Lets the option parser stop at
29           the first non-option argument. This can be used to parse
30           sub-commands that take options themselves.
31
32       --sq-quote
33           Use git rev-parse in shell quoting mode (see SQ-QUOTE section
34           below). In contrast to the --sq option below, this mode does only
35           quoting. Nothing else is done to command input.
36
37       --revs-only
38           Do not output flags and parameters not meant for git rev-list
39           command.
40
41       --no-revs
42           Do not output flags and parameters meant for git rev-list command.
43
44       --flags
45           Do not output non-flag parameters.
46
47       --no-flags
48           Do not output flag parameters.
49
50       --default <arg>
51           If there is no parameter given by the user, use <arg> instead.
52
53       --verify
54           The parameter given must be usable as a single, valid object name.
55           Otherwise barf and abort.
56
57       -q, --quiet
58           Only meaningful in --verify mode. Do not output an error message if
59           the first argument is not a valid object name; instead exit with
60           non-zero status silently.
61
62       --sq
63           Usually the output is made one line per flag and parameter. This
64           option makes output a single line, properly quoted for consumption
65           by shell. Useful when you expect your parameter to contain
66           whitespaces and newlines (e.g. when using pickaxe -S with git
67           diff-*). In contrast to the --sq-quote option, the command input is
68           still interpreted as usual.
69
70       --not
71           When showing object names, prefix them with ^ and strip ^ prefix
72           from the object names that already have one.
73
74       --symbolic
75           Usually the object names are output in SHA1 form (with possible ^
76           prefix); this option makes them output in a form as close to the
77           original input as possible.
78
79       --symbolic-full-name
80           This is similar to --symbolic, but it omits input that are not refs
81           (i.e. branch or tag names; or more explicitly disambiguating
82           "heads/master" form, when you want to name the "master" branch when
83           there is an unfortunately named tag "master"), and show them as
84           full refnames (e.g. "refs/heads/master").
85
86       --abbrev-ref[=(strict|loose)]
87           A non-ambiguous short name of the objects name. The option
88           core.warnAmbiguousRefs is used to select the strict abbreviation
89           mode.
90
91       --all
92           Show all refs found in refs/.
93
94       --branches[=pattern], --tags[=pattern], --remotes[=pattern]
95           Show all branches, tags, or remote-tracking branches, respectively
96           (i.e., refs found in refs/heads, refs/tags, or refs/remotes,
97           respectively).
98
99           If a pattern is given, only refs matching the given shell glob are
100           shown. If the pattern does not contain a globbing character (?, *,
101           or [), it is turned into a prefix match by appending /*.
102
103       --glob=pattern
104           Show all refs matching the shell glob pattern pattern. If the
105           pattern does not start with refs/, this is automatically prepended.
106           If the pattern does not contain a globbing character (?, *, or [),
107           it is turned into a prefix match by appending /*.
108
109       --show-toplevel
110           Show the absolute path of the top-level directory.
111
112       --show-prefix
113           When the command is invoked from a subdirectory, show the path of
114           the current directory relative to the top-level directory.
115
116       --show-cdup
117           When the command is invoked from a subdirectory, show the path of
118           the top-level directory relative to the current directory
119           (typically a sequence of "../", or an empty string).
120
121       --git-dir
122           Show $GIT_DIR if defined. Otherwise show the path to the .git
123           directory, relative to the current directory.
124
125           If $GIT_DIR is not defined and the current directory is not
126           detected to lie in a git repository or work tree print a message to
127           stderr and exit with nonzero status.
128
129       --is-inside-git-dir
130           When the current working directory is below the repository
131           directory print "true", otherwise "false".
132
133       --is-inside-work-tree
134           When the current working directory is inside the work tree of the
135           repository print "true", otherwise "false".
136
137       --is-bare-repository
138           When the repository is bare print "true", otherwise "false".
139
140       --local-env-vars
141           List the GIT_* environment variables that are local to the
142           repository (e.g. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR).
143           Only the names of the variables are listed, not their value, even
144           if they are set.
145
146       --short, --short=number
147           Instead of outputting the full SHA1 values of object names try to
148           abbreviate them to a shorter unique name. When no length is
149           specified 7 is used. The minimum length is 4.
150
151       --since=datestring, --after=datestring
152           Parse the date string, and output the corresponding --max-age=
153           parameter for git rev-list.
154
155       --until=datestring, --before=datestring
156           Parse the date string, and output the corresponding --min-age=
157           parameter for git rev-list.
158
159       <args>...
160           Flags and parameters to be parsed.
161

SPECIFYING REVISIONS

163       A revision parameter typically, but not necessarily, names a commit
164       object. They use what is called an extended SHA1 syntax. Here are
165       various ways to spell object names. The ones listed near the end of
166       this list are to name trees and blobs contained in a commit.
167
168       ·   The full SHA1 object name (40-byte hexadecimal string), or a
169           substring of such that is unique within the repository. E.g.
170           dae86e1950b1277e545cee180551750029cfe735 and dae86e both name the
171           same commit object if there are no other object in your repository
172           whose object name starts with dae86e.
173
174       ·   An output from git describe; i.e. a closest tag, optionally
175           followed by a dash and a number of commits, followed by a dash, a
176           g, and an abbreviated object name.
177
178       ·   A symbolic ref name. E.g.  master typically means the commit object
179           referenced by refs/heads/master. If you happen to have both
180           heads/master and tags/master, you can explicitly say heads/master
181           to tell git which one you mean. When ambiguous, a <name> is
182           disambiguated by taking the first match in the following rules:
183
184            1. if $GIT_DIR/<name> exists, that is what you mean (this is
185               usually useful only for HEAD, FETCH_HEAD, ORIG_HEAD and
186               MERGE_HEAD);
187
188            2. otherwise, refs/<name> if exists;
189
190            3. otherwise, refs/tags/<name> if exists;
191
192            4. otherwise, refs/heads/<name> if exists;
193
194            5. otherwise, refs/remotes/<name> if exists;
195
196            6. otherwise, refs/remotes/<name>/HEAD if exists.
197
198               HEAD names the commit your changes in the working tree is based
199               on. FETCH_HEAD records the branch you fetched from a remote
200               repository with your last git fetch invocation. ORIG_HEAD is
201               created by commands that moves your HEAD in a drastic way, to
202               record the position of the HEAD before their operation, so that
203               you can change the tip of the branch back to the state before
204               you ran them easily. MERGE_HEAD records the commit(s) you are
205               merging into your branch when you run git merge.
206
207               Note that any of the refs/* cases above may come either from
208               the $GIT_DIR/refs directory or from the $GIT_DIR/packed-refs
209               file.
210
211       ·   A ref followed by the suffix @ with a date specification enclosed
212           in a brace pair (e.g.  {yesterday}, {1 month 2 weeks 3 days 1 hour
213           1 second ago} or {1979-02-26 18:30:00}) to specify the value of the
214           ref at a prior point in time. This suffix may only be used
215           immediately following a ref name and the ref must have an existing
216           log ($GIT_DIR/logs/<ref>). Note that this looks up the state of
217           your local ref at a given time; e.g., what was in your local master
218           branch last week. If you want to look at commits made during
219           certain times, see --since and --until.
220
221       ·   A ref followed by the suffix @ with an ordinal specification
222           enclosed in a brace pair (e.g.  {1}, {15}) to specify the n-th
223           prior value of that ref. For example master@{1} is the immediate
224           prior value of master while master@{5} is the 5th prior value of
225           master. This suffix may only be used immediately following a ref
226           name and the ref must have an existing log ($GIT_DIR/logs/<ref>).
227
228       ·   You can use the @ construct with an empty ref part to get at a
229           reflog of the current branch. For example, if you are on the branch
230           blabla, then @{1} means the same as blabla@{1}.
231
232       ·   The special construct @{-<n>} means the <n>th branch checked out
233           before the current one.
234
235       ·   The suffix @{upstream} to a ref (short form ref@{u}) refers to the
236           branch the ref is set to build on top of. Missing ref defaults to
237           the current branch.
238
239       ·   A suffix ^ to a revision parameter (e.g.  HEAD^) means the first
240           parent of that commit object.  ^<n> means the <n>th parent (i.e.
241           rev^ is equivalent to rev^1). As a special rule, rev^0 means the
242           commit itself and is used when rev is the object name of a tag
243           object that refers to a commit object.
244
245       ·   A suffix ~<n> to a revision parameter means the commit object that
246           is the <n>th generation grand-parent of the named commit object,
247           following only the first parent. I.e. rev~3 is equivalent to rev^^^
248           which is equivalent to rev^1^1^1. See below for a illustration of
249           the usage of this form.
250
251       ·   A suffix ^ followed by an object type name enclosed in brace pair
252           (e.g.  v0.99.8^{commit}) means the object could be a tag, and
253           dereference the tag recursively until an object of that type is
254           found or the object cannot be dereferenced anymore (in which case,
255           barf).  rev^0 introduced earlier is a short-hand for rev^{commit}.
256
257       ·   A suffix ^ followed by an empty brace pair (e.g.  v0.99.8^{}) means
258           the object could be a tag, and dereference the tag recursively
259           until a non-tag object is found.
260
261       ·   A suffix ^ to a revision parameter followed by a brace pair that
262           contains a text led by a slash (e.g.  HEAD^{/fix nasty bug}): this
263           is the same as :/fix nasty bug syntax below except that it returns
264           the youngest matching commit which is reachable from the ref before
265           ^.
266
267       ·   A colon, followed by a slash, followed by a text (e.g.  :/fix nasty
268           bug): this names a commit whose commit message matches the
269           specified regular expression. This name returns the youngest
270           matching commit which is reachable from any ref. If the commit
271           message starts with a !, you have to repeat that; the special
272           sequence :/!, followed by something else than !  is reserved for
273           now. The regular expression can match any part of the commit
274           message. To match messages starting with a string, one can use e.g.
275           :/^foo.
276
277       ·   A suffix : followed by a path (e.g.  HEAD:README); this names the
278           blob or tree at the given path in the tree-ish object named by the
279           part before the colon.  :path (with an empty part before the colon,
280           e.g.  :README) is a special case of the syntax described next:
281           content recorded in the index at the given path. A path starting
282           with ./ or ../ is relative to current working directory. The given
283           path will be converted to be relative to working tree’s root
284           directory. This is most useful to address a blob or tree from a
285           commit or tree that has the same tree structure with the working
286           tree.
287
288       ·   A colon, optionally followed by a stage number (0 to 3) and a
289           colon, followed by a path (e.g.  :0:README); this names a blob
290           object in the index at the given path. Missing stage number (and
291           the colon that follows it, e.g.  :README) names a stage 0 entry.
292           During a merge, stage 1 is the common ancestor, stage 2 is the
293           target branch’s version (typically the current branch), and stage 3
294           is the version from the branch being merged.
295
296       Here is an illustration, by Jon Loeliger. Both commit nodes B and C are
297       parents of commit node A. Parent commits are ordered left-to-right.
298
299           G   H   I   J
300            \ /     \ /
301             D   E   F
302              \  |  / \
303               \ | /   |
304                \|/    |
305                 B     C
306                  \   /
307                   \ /
308                    A
309
310           A =      = A^0
311           B = A^   = A^1     = A~1
312           C = A^2  = A^2
313           D = A^^  = A^1^1   = A~2
314           E = B^2  = A^^2
315           F = B^3  = A^^3
316           G = A^^^ = A^1^1^1 = A~3
317           H = D^2  = B^^2    = A^^^2  = A~2^2
318           I = F^   = B^3^    = A^^3^
319           J = F^2  = B^3^2   = A^^3^2
320

SPECIFYING RANGES

322       History traversing commands such as git log operate on a set of
323       commits, not just a single commit. To these commands, specifying a
324       single revision with the notation described in the previous section
325       means the set of commits reachable from that commit, following the
326       commit ancestry chain.
327
328       To exclude commits reachable from a commit, a prefix ^ notation is
329       used. E.g. ^r1 r2 means commits reachable from r2 but exclude the ones
330       reachable from r1.
331
332       This set operation appears so often that there is a shorthand for it.
333       When you have two commits r1 and r2 (named according to the syntax
334       explained in SPECIFYING REVISIONS above), you can ask for commits that
335       are reachable from r2 excluding those that are reachable from r1 by ^r1
336       r2 and it can be written as r1..r2.
337
338       A similar notation r1...r2 is called symmetric difference of r1 and r2
339       and is defined as r1 r2 --not $(git merge-base --all r1 r2). It is the
340       set of commits that are reachable from either one of r1 or r2 but not
341       from both.
342
343       Two other shorthands for naming a set that is formed by a commit and
344       its parent commits exist. The r1^@ notation means all parents of r1.
345       r1^! includes commit r1 but excludes all of its parents.
346
347       Here are a handful of examples:
348
349           D                G H D
350           D F              G H I J D F
351           ^G D             H D
352           ^D B             E I J F B
353           B...C            G H D E B C
354           ^D B C           E I J F B C
355           C^@              I J F
356           F^! D            G H D F
357

PARSEOPT

359       In --parseopt mode, git rev-parse helps massaging options to bring to
360       shell scripts the same facilities C builtins have. It works as an
361       option normalizer (e.g. splits single switches aggregate values), a bit
362       like getopt(1) does.
363
364       It takes on the standard input the specification of the options to
365       parse and understand, and echoes on the standard output a string
366       suitable for sh(1) eval to replace the arguments with normalized ones.
367       In case of error, it outputs usage on the standard error stream, and
368       exits with code 129.
369
370       Note: Make sure you quote the result when passing it to eval. See below
371       for an example.
372
373   Input Format
374       git rev-parse --parseopt input format is fully text based. It has two
375       parts, separated by a line that contains only --. The lines before the
376       separator (should be more than one) are used for the usage. The lines
377       after the separator describe the options.
378
379       Each line of options has this format:
380
381           <opt_spec><flags>* SP+ help LF
382
383
384       <opt_spec>
385           its format is the short option character, then the long option name
386           separated by a comma. Both parts are not required, though at least
387           one is necessary.  h,help, dry-run and f are all three correct
388           <opt_spec>.
389
390       <flags>
391
392           <flags> are of *, =, ?  or !.
393
394           ·   Use = if the option takes an argument.
395
396           ·   Use ?  to mean that the option is optional (though its use is
397               discouraged).
398
399           ·   Use * to mean that this option should not be listed in the
400               usage generated for the -h argument. It’s shown for --help-all
401               as documented in gitcli(7).
402
403           ·   Use !  to not make the corresponding negated long option
404               available.
405
406       The remainder of the line, after stripping the spaces, is used as the
407       help associated to the option.
408
409       Blank lines are ignored, and lines that don’t match this specification
410       are used as option group headers (start the line with a space to create
411       such lines on purpose).
412
413   Example
414           OPTS_SPEC="\
415           some-command [options] <args>...
416
417           some-command does foo and bar!
418           --
419           h,help    show the help
420
421           foo       some nifty option --foo
422           bar=      some cool option --bar with an argument
423
424             An option group Header
425           C?        option C with an optional argument"
426
427           eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
428
429

SQ-QUOTE

431       In --sq-quote mode, git rev-parse echoes on the standard output a
432       single line suitable for sh(1) eval. This line is made by normalizing
433       the arguments following --sq-quote. Nothing other than quoting the
434       arguments is done.
435
436       If you want command input to still be interpreted as usual by git
437       rev-parse before the output is shell quoted, see the --sq option.
438
439   Example
440           $ cat >your-git-script.sh <<\EOF
441           #!/bin/sh
442           args=$(git rev-parse --sq-quote "$@")   # quote user-supplied arguments
443           command="git frotz -n24 $args"          # and use it inside a handcrafted
444                                                   # command line
445           eval "$command"
446           EOF
447
448           $ sh your-git-script.sh "a b'c"
449
450

EXAMPLES

452       ·   Print the object name of the current commit:
453
454               $ git rev-parse --verify HEAD
455
456
457       ·   Print the commit object name from the revision in the $REV shell
458           variable:
459
460               $ git rev-parse --verify $REV
461
462           This will error out if $REV is empty or not a valid revision.
463
464       ·   Same as above:
465
466               $ git rev-parse --default master --verify $REV
467
468           but if $REV is empty, the commit object name from master will be
469           printed.
470

AUTHOR

472       Written by Linus Torvalds <torvalds@osdl.org[1]> . Junio C Hamano
473       <gitster@pobox.com[2]> and Pierre Habouzit <madcoder@debian.org[3]>
474

DOCUMENTATION

476       Documentation by Junio C Hamano and the git-list
477       <git@vger.kernel.org[4]>.
478

GIT

480       Part of the git(1) suite
481

NOTES

483        1. torvalds@osdl.org
484           mailto:torvalds@osdl.org
485
486        2. gitster@pobox.com
487           mailto:gitster@pobox.com
488
489        3. madcoder@debian.org
490           mailto:madcoder@debian.org
491
492        4. git@vger.kernel.org
493           mailto:git@vger.kernel.org
494
495
496
497Git 1.7.4.4                       04/11/2011                  GIT-REV-PARSE(1)
Impressum