blob: 19b12b6d43ce5bfeb2dba36e30640ddaf0aca664 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-rev-parse(1)
2================
3
4NAME
5----
Junio C Hamano01078922006-03-10 00:31:476git-rev-parse - Pick out and massage parameters
Junio C Hamano1a4e8412005-12-27 08:17:237
8
9SYNOPSIS
10--------
Junio C Hamano15567bc2011-07-23 00:51:5911[verse]
Junio C Hamanoc9cb5172018-06-01 07:13:4412'git rev-parse' [<options>] <args>...
Junio C Hamano1a4e8412005-12-27 08:17:2313
14DESCRIPTION
15-----------
16
Junio C Hamano076ffcc2013-02-06 05:13:2117Many Git porcelainish commands take mixture of flags
Junio C Hamano1a4e8412005-12-27 08:17:2318(i.e. parameters that begin with a dash '-') and parameters
Junio C Hamano1aa40d22010-01-21 17:46:4319meant for the underlying 'git rev-list' command they use internally
Junio C Hamanofce7c7e2008-07-02 03:06:3820and flags and parameters for the other commands they use
Junio C Hamano1aa40d22010-01-21 17:46:4321downstream of 'git rev-list'. This command is used to
Junio C Hamano1a4e8412005-12-27 08:17:2322distinguish between them.
23
24
25OPTIONS
26-------
Junio C Hamano0241d052013-08-30 23:52:1727
28Operation Modes
29~~~~~~~~~~~~~~~
30
31Each of these options must appear first on the command line.
32
Junio C Hamanoe1258662007-11-19 05:03:1933--parseopt::
Junio C Hamano1aa40d22010-01-21 17:46:4334Use 'git rev-parse' in option parsing mode (see PARSEOPT section below).
Junio C Hamanoe1258662007-11-19 05:03:1935
Junio C Hamano0241d052013-08-30 23:52:1736--sq-quote::
37Use 'git rev-parse' in shell quoting mode (see SQ-QUOTE
38section below). In contrast to the `--sq` option below, this
39mode does only quoting. Nothing else is done to command input.
40
41Options for --parseopt
42~~~~~~~~~~~~~~~~~~~~~~
43
Junio C Hamanoa9499de2009-04-30 03:38:4844--keep-dashdash::
Junio C Hamanoe1258662007-11-19 05:03:1945Only meaningful in `--parseopt` mode. Tells the option parser to echo
46out the first `--` met instead of skipping it.
47
Junio C Hamanoccc4d372009-07-06 18:05:3848--stop-at-non-option::
49Only meaningful in `--parseopt` mode. Lets the option parser stop at
50the first non-option argument. This can be used to parse sub-commands
Junio C Hamano167b1382010-01-31 23:04:3151that take options themselves.
Junio C Hamanoccc4d372009-07-06 18:05:3852
Junio C Hamanof079f702013-12-06 23:43:1853--stuck-long::
54Only meaningful in `--parseopt` mode. Output the options in their
55long form if available, and with their arguments stuck.
56
Junio C Hamano0241d052013-08-30 23:52:1757Options for Filtering
58~~~~~~~~~~~~~~~~~~~~~
Junio C Hamano7ae18252009-05-23 09:53:3259
Junio C Hamano1a4e8412005-12-27 08:17:2360--revs-only::
61Do not output flags and parameters not meant for
Junio C Hamano1aa40d22010-01-21 17:46:4362'git rev-list' command.
Junio C Hamano1a4e8412005-12-27 08:17:2363
64--no-revs::
65Do not output flags and parameters meant for
Junio C Hamano1aa40d22010-01-21 17:46:4366'git rev-list' command.
Junio C Hamano1a4e8412005-12-27 08:17:2367
68--flags::
69Do not output non-flag parameters.
70
71--no-flags::
72Do not output flag parameters.
73
Junio C Hamano0241d052013-08-30 23:52:1774Options for Output
75~~~~~~~~~~~~~~~~~~
76
Junio C Hamano1a4e8412005-12-27 08:17:2377--default <arg>::
78If there is no parameter given by the user, use `<arg>`
79instead.
80
Junio C Hamanoa1952302013-07-01 21:31:1881--prefix <arg>::
82Behave as if 'git rev-parse' was invoked from the `<arg>`
83subdirectory of the working tree. Any relative filenames are
84resolved as if they are prefixed by `<arg>` and will be printed
85in that form.
86+
87This can be used to convert arguments to a command run in a subdirectory
88so that they can still be used after moving to the top-level of the
89repository. For example:
90+
91----
92prefix=$(git rev-parse --show-prefix)
93cd "$(git rev-parse --show-toplevel)"
Junio C Hamanodda5d0f2017-01-19 23:33:3194# rev-parse provides the -- needed for 'set'
95eval "set $(git rev-parse --sq --prefix "$prefix" -- "$@")"
Junio C Hamanoa1952302013-07-01 21:31:1896----
97
Junio C Hamano1a4e8412005-12-27 08:17:2398--verify::
Junio C Hamanoedf80bd2013-04-05 22:14:3699Verify that exactly one parameter is provided, and that it
100can be turned into a raw 20-byte SHA-1 that can be used to
101access the object database. If so, emit it to the standard
102output; otherwise, error out.
103+
104If you want to make sure that the output actually names an object in
105your object database and/or can be used as a specific type of object
Junio C Hamano1dbca522015-05-22 20:48:55106you require, you can add the `^{type}` peeling operator to the parameter.
Junio C Hamanoedf80bd2013-04-05 22:14:36107For example, `git rev-parse "$VAR^{commit}"` will make sure `$VAR`
108names an existing object that is a commit-ish (i.e. a commit, or an
109annotated tag that points at a commit). To make sure that `$VAR`
110names an existing object of any type, `git rev-parse "$VAR^{object}"`
111can be used.
Junio C Hamano1a4e8412005-12-27 08:17:23112
Junio C Hamanoeb415992008-06-08 22:49:47113-q::
114--quiet::
Junio C Hamano9ab87672008-04-28 08:40:29115Only meaningful in `--verify` mode. Do not output an error
116message if the first argument is not a valid object name;
117instead exit with non-zero status silently.
Junio C Hamano00b9f1a2014-09-29 23:11:28118SHA-1s for valid object names are printed to stdout on success.
Junio C Hamano9ab87672008-04-28 08:40:29119
Junio C Hamano1a4e8412005-12-27 08:17:23120--sq::
121Usually the output is made one line per flag and
122parameter. This option makes output a single line,
123properly quoted for consumption by shell. Useful when
124you expect your parameter to contain whitespaces and
125newlines (e.g. when using pickaxe `-S` with
Junio C Hamano2db3e752010-09-03 21:33:06126'git diff-{asterisk}'). In contrast to the `--sq-quote` option,
Junio C Hamano7ae18252009-05-23 09:53:32127the command input is still interpreted as usual.
Junio C Hamano1a4e8412005-12-27 08:17:23128
Junio C Hamanoe0e20df2017-06-04 02:10:21129--short[=length]::
130Same as `--verify` but shortens the object name to a unique
131prefix with at least `length` characters. The minimum length
132is 4, the default is the effective value of the `core.abbrev`
133configuration variable (see linkgit:git-config[1]).
134
Junio C Hamano1a4e8412005-12-27 08:17:23135--not::
136When showing object names, prefix them with '{caret}' and
137strip '{caret}' prefix from the object names that already have
138one.
139
Junio C Hamano0241d052013-08-30 23:52:17140--abbrev-ref[=(strict|loose)]::
141A non-ambiguous short name of the objects name.
142The option core.warnAmbiguousRefs is used to select the strict
143abbreviation mode.
144
Junio C Hamano1a4e8412005-12-27 08:17:23145--symbolic::
Junio C Hamanoe3f080d2013-04-22 02:27:13146Usually the object names are output in SHA-1 form (with
Junio C Hamano1a4e8412005-12-27 08:17:23147possible '{caret}' prefix); this option makes them output in a
148form as close to the original input as possible.
149
Junio C Hamano35738e82008-01-07 07:55:46150--symbolic-full-name::
Junio C Hamano1dbca522015-05-22 20:48:55151This is similar to --symbolic, but it omits input that
Junio C Hamano35738e82008-01-07 07:55:46152are not refs (i.e. branch or tag names; or more
153explicitly disambiguating "heads/master" form, when you
154want to name the "master" branch when there is an
155unfortunately named tag "master"), and show them as full
156refnames (e.g. "refs/heads/master").
Junio C Hamano1a4e8412005-12-27 08:17:23157
Junio C Hamano0241d052013-08-30 23:52:17158Options for Objects
159~~~~~~~~~~~~~~~~~~~
Junio C Hamanobb300642012-07-22 21:09:14160
Junio C Hamano1a4e8412005-12-27 08:17:23161--all::
Junio C Hamano4fdccb22010-02-19 09:58:14162Show all refs found in `refs/`.
Junio C Hamano1a4e8412005-12-27 08:17:23163
Junio C Hamano57827fb2010-01-23 03:02:50164--branches[=pattern]::
165--tags[=pattern]::
166--remotes[=pattern]::
167Show all branches, tags, or remote-tracking branches,
Junio C Hamano4fdccb22010-02-19 09:58:14168respectively (i.e., refs found in `refs/heads`,
169`refs/tags`, or `refs/remotes`, respectively).
Junio C Hamano57827fb2010-01-23 03:02:50170+
171If a `pattern` is given, only refs matching the given shell glob are
172shown. If the pattern does not contain a globbing character (`?`,
Junio C Hamanob76a6862012-05-02 22:02:46173`*`, or `[`), it is turned into a prefix match by appending `/*`.
Junio C Hamano6959c6c2006-05-17 10:34:11174
Junio C Hamano57827fb2010-01-23 03:02:50175--glob=pattern::
176Show all refs matching the shell glob pattern `pattern`. If
177the pattern does not start with `refs/`, this is automatically
178prepended. If the pattern does not contain a globbing
Junio C Hamanob76a6862012-05-02 22:02:46179character (`?`, `*`, or `[`), it is turned into a prefix
180match by appending `/*`.
Junio C Hamano6959c6c2006-05-17 10:34:11181
Junio C Hamanof079f702013-12-06 23:43:18182--exclude=<glob-pattern>::
183Do not include refs matching '<glob-pattern>' that the next `--all`,
184`--branches`, `--tags`, `--remotes`, or `--glob` would otherwise
185consider. Repetitions of this option accumulate exclusion patterns
186up to the next `--all`, `--branches`, `--tags`, `--remotes`, or
187`--glob` option (other options or arguments do not clear
Junio C Hamanofb5ffde2014-11-04 22:38:56188accumulated patterns).
Junio C Hamanof079f702013-12-06 23:43:18189+
190The patterns given should not begin with `refs/heads`, `refs/tags`, or
191`refs/remotes` when applied to `--branches`, `--tags`, or `--remotes`,
192respectively, and they must begin with `refs/` when applied to `--glob`
193or `--all`. If a trailing '/{asterisk}' is intended, it must be given
194explicitly.
195
Junio C Hamano0241d052013-08-30 23:52:17196--disambiguate=<prefix>::
197Show every object whose name begins with the given prefix.
198The <prefix> must be at least 4 hexadecimal digits long to
199avoid listing each and every object in the repository by
200mistake.
Junio C Hamanoa9701f02010-01-21 00:42:16201
Junio C Hamano0241d052013-08-30 23:52:17202Options for Files
203~~~~~~~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:23204
Junio C Hamano0241d052013-08-30 23:52:17205--local-env-vars::
206List the GIT_* environment variables that are local to the
207repository (e.g. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR).
208Only the names of the variables are listed, not their value,
209even if they are set.
Junio C Hamano1a4e8412005-12-27 08:17:23210
Junio C Hamanoe246e3b2006-02-19 08:45:18211--git-dir::
Junio C Hamano3609b332010-12-29 01:34:52212Show `$GIT_DIR` if defined. Otherwise show the path to
Junio C Hamano35cd2a82012-05-23 22:01:13213the .git directory. The path shown, when relative, is
214relative to the current working directory.
Junio C Hamano3609b332010-12-29 01:34:52215+
216If `$GIT_DIR` is not defined and the current directory
Junio C Hamano076ffcc2013-02-06 05:13:21217is not detected to lie in a Git repository or work tree
Junio C Hamano3609b332010-12-29 01:34:52218print a message to stderr and exit with nonzero status.
Junio C Hamanoe246e3b2006-02-19 08:45:18219
Junio C Hamanocbe0eb22017-02-27 23:37:49220--absolute-git-dir::
221Like `--git-dir`, but its output is always the canonicalized
222absolute path.
223
Junio C Hamano4cc4a842015-05-11 22:41:02224--git-common-dir::
225Show `$GIT_COMMON_DIR` if defined, else `$GIT_DIR`.
226
Junio C Hamanoee695f22007-06-21 00:35:36227--is-inside-git-dir::
Junio C Hamanod526ba92007-07-02 00:17:42228When the current working directory is below the repository
229directory print "true", otherwise "false".
230
231--is-inside-work-tree::
232When the current working directory is inside the work tree of the
233repository print "true", otherwise "false".
234
235--is-bare-repository::
236When the repository is bare print "true", otherwise "false".
Junio C Hamanoee695f22007-06-21 00:35:36237
Junio C Hamanod4bbec02017-09-25 07:24:53238--is-shallow-repository::
239When the repository is shallow print "true", otherwise "false".
240
Junio C Hamano0241d052013-08-30 23:52:17241--resolve-git-dir <path>::
242Check if <path> is a valid repository or a gitfile that
243points at a valid repository, and print the location of the
244repository. If <path> is a gitfile then the resolved path
245to the real repository is printed.
Junio C Hamano636c8b22010-03-07 22:25:17246
Junio C Hamano4cc4a842015-05-11 22:41:02247--git-path <path>::
248Resolve "$GIT_DIR/<path>" and takes other path relocation
249variables such as $GIT_OBJECT_DIRECTORY,
250$GIT_INDEX_FILE... into account. For example, if
251$GIT_OBJECT_DIRECTORY is set to /foo/bar then "git rev-parse
252--git-path objects/abc" returns /foo/bar/abc.
253
Junio C Hamano0241d052013-08-30 23:52:17254--show-cdup::
255When the command is invoked from a subdirectory, show the
256path of the top-level directory relative to the current
257directory (typically a sequence of "../", or an empty string).
258
259--show-prefix::
260When the command is invoked from a subdirectory, show the
261path of the current directory relative to the top-level
262directory.
263
264--show-toplevel::
Junio C Hamanob3f862c2019-12-05 22:22:00265Show the absolute path of the top-level directory of the working
266tree. If there is no working tree, report an error.
Junio C Hamano0241d052013-08-30 23:52:17267
Junio C Hamanoce019c02017-10-30 05:57:46268--show-superproject-working-tree::
Junio C Hamano3d4a66d2017-03-17 21:07:26269Show the absolute path of the root of the superproject's
270working tree (if exists) that uses the current repository as
271its submodule. Outputs nothing if the current repository is
272not used as a submodule by any project.
273
Junio C Hamano6f0c9442014-07-16 21:51:32274--shared-index-path::
275Show the path to the shared index file in split index mode, or
276empty if not in split-index mode.
277
Junio C Hamano8ac8a3d2019-11-11 04:33:46278--show-object-format[=(storage|input|output)]::
279Show the object format (hash algorithm) used for the repository
280for storage inside the `.git` directory, input, or output. For
281input, multiple algorithms may be printed, space-separated.
282If not specified, the default is "storage".
283
284
Junio C Hamano0241d052013-08-30 23:52:17285Other Options
286~~~~~~~~~~~~~
Junio C Hamanoe246e3b2006-02-19 08:45:18287
Junio C Hamanoeb415992008-06-08 22:49:47288--since=datestring::
289--after=datestring::
Junio C Hamanofce7c7e2008-07-02 03:06:38290Parse the date string, and output the corresponding
Junio C Hamano1aa40d22010-01-21 17:46:43291--max-age= parameter for 'git rev-list'.
Junio C Hamano1a4e8412005-12-27 08:17:23292
Junio C Hamanoeb415992008-06-08 22:49:47293--until=datestring::
294--before=datestring::
Junio C Hamanofce7c7e2008-07-02 03:06:38295Parse the date string, and output the corresponding
Junio C Hamano1aa40d22010-01-21 17:46:43296--min-age= parameter for 'git rev-list'.
Junio C Hamano1a4e8412005-12-27 08:17:23297
298<args>...::
299Flags and parameters to be parsed.
300
301
Junio C Hamano78e3a782010-07-15 22:24:45302include::revisions.txt[]
Junio C Hamano872c5682006-07-07 06:05:40303
Junio C Hamanoe1258662007-11-19 05:03:19304PARSEOPT
305--------
306
Junio C Hamano1aa40d22010-01-21 17:46:43307In `--parseopt` mode, 'git rev-parse' helps massaging options to bring to shell
Junio C Hamanoe1258662007-11-19 05:03:19308scripts the same facilities C builtins have. It works as an option normalizer
309(e.g. splits single switches aggregate values), a bit like `getopt(1)` does.
310
311It takes on the standard input the specification of the options to parse and
Junio C Hamanoa9788762010-08-03 15:15:54312understand, and echoes on the standard output a string suitable for `sh(1)` `eval`
Junio C Hamanoe1258662007-11-19 05:03:19313to replace the arguments with normalized ones. In case of error, it outputs
314usage on the standard error stream, and exits with code 129.
315
Junio C Hamanoa9788762010-08-03 15:15:54316Note: Make sure you quote the result when passing it to `eval`. See
317below for an example.
318
Junio C Hamanoe1258662007-11-19 05:03:19319Input Format
320~~~~~~~~~~~~
321
Junio C Hamano1aa40d22010-01-21 17:46:43322'git rev-parse --parseopt' input format is fully text based. It has two parts,
Junio C Hamanoe1258662007-11-19 05:03:19323separated by a line that contains only `--`. The lines before the separator
Junio C Hamano52b6ba32014-04-01 00:26:48324(should be one or more) are used for the usage.
Junio C Hamanoe1258662007-11-19 05:03:19325The lines after the separator describe the options.
326
327Each line of options has this format:
328
329------------
Junio C Hamanod75148a2014-04-08 19:48:38330<opt-spec><flags>*<arg-hint>? SP+ help LF
Junio C Hamanoe1258662007-11-19 05:03:19331------------
332
Junio C Hamanod75148a2014-04-08 19:48:38333`<opt-spec>`::
Junio C Hamanoe1258662007-11-19 05:03:19334its format is the short option character, then the long option name
335separated by a comma. Both parts are not required, though at least one
Junio C Hamanod7ed4042015-08-03 19:43:00336is necessary. May not contain any of the `<flags>` characters.
337`h,help`, `dry-run` and `f` are examples of correct `<opt-spec>`.
Junio C Hamanoe1258662007-11-19 05:03:19338
Junio C Hamanobb343172008-03-09 10:39:09339`<flags>`::
340`<flags>` are of `*`, `=`, `?` or `!`.
341* Use `=` if the option takes an argument.
342
Junio C Hamanof079f702013-12-06 23:43:18343* Use `?` to mean that the option takes an optional argument. You
344 probably want to use the `--stuck-long` mode to be able to
345 unambiguously parse the optional argument.
Junio C Hamanobb343172008-03-09 10:39:09346
347* Use `*` to mean that this option should not be listed in the usage
348 generated for the `-h` argument. It's shown for `--help-all` as
Junio C Hamano2fbcd212008-05-14 22:26:07349 documented in linkgit:gitcli[7].
Junio C Hamanobb343172008-03-09 10:39:09350
351* Use `!` to not make the corresponding negated long option available.
Junio C Hamanoe1258662007-11-19 05:03:19352
Junio C Hamanod75148a2014-04-08 19:48:38353`<arg-hint>`::
354`<arg-hint>`, if specified, is used as a name of the argument in the
355help output, for options that take arguments. `<arg-hint>` is
356terminated by the first whitespace. It is customary to use a
357dash to separate words in a multi-word argument hint.
Junio C Hamano52b6ba32014-04-01 00:26:48358
Junio C Hamanoe1258662007-11-19 05:03:19359The remainder of the line, after stripping the spaces, is used
360as the help associated to the option.
361
362Blank lines are ignored, and lines that don't match this specification are used
363as option group headers (start the line with a space to create such
364lines on purpose).
365
366Example
367~~~~~~~
368
369------------
370OPTS_SPEC="\
Junio C Hamanoc9cb5172018-06-01 07:13:44371some-command [<options>] <args>...
Junio C Hamanoe1258662007-11-19 05:03:19372
373some-command does foo and bar!
374--
375h,help show the help
376
377foo some nifty option --foo
378bar= some cool option --bar with an argument
Junio C Hamano52b6ba32014-04-01 00:26:48379baz=arg another cool option --baz with a named argument
380qux?path qux may take a path argument but has meaning by itself
Junio C Hamanoe1258662007-11-19 05:03:19381
382 An option group Header
383C? option C with an optional argument"
384
Junio C Hamanoa9788762010-08-03 15:15:54385eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
Junio C Hamanoe1258662007-11-19 05:03:19386------------
387
Junio C Hamano52b6ba32014-04-01 00:26:48388
389Usage text
390~~~~~~~~~~
391
392When `"$@"` is `-h` or `--help` in the above example, the following
393usage text would be shown:
394
395------------
Junio C Hamanoc9cb5172018-06-01 07:13:44396usage: some-command [<options>] <args>...
Junio C Hamano52b6ba32014-04-01 00:26:48397
398 some-command does foo and bar!
399
400 -h, --help show the help
401 --foo some nifty option --foo
402 --bar ... some cool option --bar with an argument
Junio C Hamanod75148a2014-04-08 19:48:38403 --baz <arg> another cool option --baz with a named argument
Junio C Hamano52b6ba32014-04-01 00:26:48404 --qux[=<path>] qux may take a path argument but has meaning by itself
405
406An option group Header
407 -C[...] option C with an optional argument
408------------
409
Junio C Hamano7ae18252009-05-23 09:53:32410SQ-QUOTE
411--------
412
Junio C Hamano1aa40d22010-01-21 17:46:43413In `--sq-quote` mode, 'git rev-parse' echoes on the standard output a
Junio C Hamano7ae18252009-05-23 09:53:32414single line suitable for `sh(1)` `eval`. This line is made by
415normalizing the arguments following `--sq-quote`. Nothing other than
416quoting the arguments is done.
417
418If you want command input to still be interpreted as usual by
Junio C Hamano1aa40d22010-01-21 17:46:43419'git rev-parse' before the output is shell quoted, see the `--sq`
Junio C Hamano7ae18252009-05-23 09:53:32420option.
421
422Example
423~~~~~~~
424
425------------
426$ cat >your-git-script.sh <<\EOF
427#!/bin/sh
428args=$(git rev-parse --sq-quote "$@") # quote user-supplied arguments
429command="git frotz -n24 $args" # and use it inside a handcrafted
430# command line
431eval "$command"
432EOF
433
434$ sh your-git-script.sh "a b'c"
435------------
436
Junio C Hamanofeeb1be2008-05-22 00:53:35437EXAMPLES
438--------
439
440* Print the object name of the current commit:
441+
442------------
443$ git rev-parse --verify HEAD
444------------
445
446* Print the commit object name from the revision in the $REV shell variable:
447+
448------------
Junio C Hamanoedf80bd2013-04-05 22:14:36449$ git rev-parse --verify $REV^{commit}
Junio C Hamanofeeb1be2008-05-22 00:53:35450------------
451+
452This will error out if $REV is empty or not a valid revision.
453
Junio C Hamanoedf80bd2013-04-05 22:14:36454* Similar to above:
Junio C Hamanofeeb1be2008-05-22 00:53:35455+
456------------
457$ git rev-parse --default master --verify $REV
458------------
459+
460but if $REV is empty, the commit object name from master will be printed.
461
Junio C Hamano1a4e8412005-12-27 08:17:23462GIT
463---
Junio C Hamanof7c042d2008-06-06 22:50:53464Part of the linkgit:git[1] suite