]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-rev-parse.txt
submodule: show full path in error message
[thirdparty/git.git] / Documentation / git-rev-parse.txt
CommitLineData
7fc9d69f
JH
1git-rev-parse(1)
2================
3
4NAME
5----
7bd7f280 6git-rev-parse - Pick out and massage parameters
7fc9d69f
JH
7
8
9SYNOPSIS
10--------
7791a1d9 11[verse]
b1889c36 12'git rev-parse' [ --option ] <args>...
7fc9d69f
JH
13
14DESCRIPTION
15-----------
5077fa9c 16
2de9b711 17Many Git porcelainish commands take mixture of flags
5077fa9c 18(i.e. parameters that begin with a dash '-') and parameters
0b444cdb 19meant for the underlying 'git rev-list' command they use internally
483bc4f0 20and flags and parameters for the other commands they use
0b444cdb 21downstream of 'git rev-list'. This command is used to
5077fa9c 22distinguish between them.
7fc9d69f
JH
23
24
25OPTIONS
26-------
21d47835 27--parseopt::
0b444cdb 28 Use 'git rev-parse' in option parsing mode (see PARSEOPT section below).
21d47835 29
2163e3f7 30--keep-dashdash::
21d47835
PH
31 Only meaningful in `--parseopt` mode. Tells the option parser to echo
32 out the first `--` met instead of skipping it.
33
6e0800ef
UKK
34--stop-at-non-option::
35 Only meaningful in `--parseopt` mode. Lets the option parser stop at
36 the first non-option argument. This can be used to parse sub-commands
6a5d0b0a 37 that take options themselves.
6e0800ef 38
50325377 39--sq-quote::
0b444cdb 40 Use 'git rev-parse' in shell quoting mode (see SQ-QUOTE
50325377
CC
41 section below). In contrast to the `--sq` option below, this
42 mode does only quoting. Nothing else is done to command input.
43
5077fa9c
JH
44--revs-only::
45 Do not output flags and parameters not meant for
0b444cdb 46 'git rev-list' command.
5077fa9c
JH
47
48--no-revs::
49 Do not output flags and parameters meant for
0b444cdb 50 'git rev-list' command.
5077fa9c
JH
51
52--flags::
53 Do not output non-flag parameters.
54
55--no-flags::
56 Do not output flag parameters.
57
58--default <arg>::
59 If there is no parameter given by the user, use `<arg>`
60 instead.
61
62--verify::
2db60670
MH
63 Verify that exactly one parameter is provided, and that it
64 can be turned into a raw 20-byte SHA-1 that can be used to
65 access the object database. If so, emit it to the standard
66 output; otherwise, error out.
67+
68If you want to make sure that the output actually names an object in
69your object database and/or can be used as a specific type of object
70you require, you can add "^{type}" peeling operator to the parmeter.
71For example, `git rev-parse "$VAR^{commit}"` will make sure `$VAR`
72names an existing object that is a commit-ish (i.e. a commit, or an
73annotated tag that points at a commit). To make sure that `$VAR`
74names an existing object of any type, `git rev-parse "$VAR^{object}"`
75can be used.
5077fa9c 76
3240240f
SB
77-q::
78--quiet::
b1b35969
CC
79 Only meaningful in `--verify` mode. Do not output an error
80 message if the first argument is not a valid object name;
81 instead exit with non-zero status silently.
82
5077fa9c
JH
83--sq::
84 Usually the output is made one line per flag and
85 parameter. This option makes output a single line,
86 properly quoted for consumption by shell. Useful when
87 you expect your parameter to contain whitespaces and
88 newlines (e.g. when using pickaxe `-S` with
4cacbf67 89 'git diff-{asterisk}'). In contrast to the `--sq-quote` option,
50325377 90 the command input is still interpreted as usual.
5077fa9c
JH
91
92--not::
babfaba2
JF
93 When showing object names, prefix them with '{caret}' and
94 strip '{caret}' prefix from the object names that already have
5077fa9c
JH
95 one.
96
97--symbolic::
d5fa1f1a 98 Usually the object names are output in SHA-1 form (with
babfaba2 99 possible '{caret}' prefix); this option makes them output in a
5077fa9c
JH
100 form as close to the original input as possible.
101
a6d97d49
JH
102--symbolic-full-name::
103 This is similar to \--symbolic, but it omits input that
104 are not refs (i.e. branch or tag names; or more
105 explicitly disambiguating "heads/master" form, when you
106 want to name the "master" branch when there is an
107 unfortunately named tag "master"), and show them as full
108 refnames (e.g. "refs/heads/master").
5077fa9c 109
0adda936 110--abbrev-ref[=(strict|loose)]::
a45d3469
BW
111 A non-ambiguous short name of the objects name.
112 The option core.warnAmbiguousRefs is used to select the strict
113 abbreviation mode.
114
957d7406
JH
115--disambiguate=<prefix>::
116 Show every object whose name begins with the given prefix.
117 The <prefix> must be at least 4 hexadecimal digits long to
118 avoid listing each and every object in the repository by
119 mistake.
120
5077fa9c 121--all::
cc1b8d8b 122 Show all refs found in `refs/`.
5077fa9c 123
b09fe971 124--branches[=pattern]::
b09fe971 125--tags[=pattern]::
b09fe971 126--remotes[=pattern]::
e2b53e58 127 Show all branches, tags, or remote-tracking branches,
cc1b8d8b
JK
128 respectively (i.e., refs found in `refs/heads`,
129 `refs/tags`, or `refs/remotes`, respectively).
e2b53e58
TR
130+
131If a `pattern` is given, only refs matching the given shell glob are
132shown. If the pattern does not contain a globbing character (`?`,
6cf378f0 133`*`, or `[`), it is turned into a prefix match by appending `/*`.
e2b53e58
TR
134
135--glob=pattern::
136 Show all refs matching the shell glob pattern `pattern`. If
137 the pattern does not start with `refs/`, this is automatically
138 prepended. If the pattern does not contain a globbing
6cf378f0
JK
139 character (`?`, `*`, or `[`), it is turned into a prefix
140 match by appending `/*`.
a62be77f 141
7cceca5c
SD
142--show-toplevel::
143 Show the absolute path of the top-level directory.
144
5077fa9c 145--show-prefix::
5f94c730 146 When the command is invoked from a subdirectory, show the
5077fa9c
JH
147 path of the current directory relative to the top-level
148 directory.
7fc9d69f 149
5f94c730
JH
150--show-cdup::
151 When the command is invoked from a subdirectory, show the
152 path of the top-level directory relative to the current
153 directory (typically a sequence of "../", or an empty string).
154
735d80b3 155--git-dir::
80d868b0 156 Show `$GIT_DIR` if defined. Otherwise show the path to
d0740ce0
JS
157 the .git directory. The path shown, when relative, is
158 relative to the current working directory.
80d868b0
JN
159+
160If `$GIT_DIR` is not defined and the current directory
2de9b711 161is not detected to lie in a Git repository or work tree
80d868b0 162print a message to stderr and exit with nonzero status.
735d80b3 163
c9bf7be2 164--is-inside-git-dir::
4faac246
ML
165 When the current working directory is below the repository
166 directory print "true", otherwise "false".
167
892c41b9
ML
168--is-inside-work-tree::
169 When the current working directory is inside the work tree of the
170 repository print "true", otherwise "false".
171
493c774e
ML
172--is-bare-repository::
173 When the repository is bare print "true", otherwise "false".
c9bf7be2 174
94c8ccaa
GB
175--local-env-vars::
176 List the GIT_* environment variables that are local to the
177 repository (e.g. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR).
178 Only the names of the variables are listed, not their value,
179 even if they are set.
180
3240240f
SB
181--short::
182--short=number::
d5fa1f1a 183 Instead of outputting the full SHA-1 values of object names try to
abda1ef5 184 abbreviate them to a shorter unique name. When no length is specified
735d80b3
JF
185 7 is used. The minimum length is 4.
186
3240240f
SB
187--since=datestring::
188--after=datestring::
483bc4f0 189 Parse the date string, and output the corresponding
0b444cdb 190 --max-age= parameter for 'git rev-list'.
a3114b34 191
3240240f
SB
192--until=datestring::
193--before=datestring::
483bc4f0 194 Parse the date string, and output the corresponding
0b444cdb 195 --min-age= parameter for 'git rev-list'.
a3114b34 196
7fc9d69f 197<args>...::
5077fa9c 198 Flags and parameters to be parsed.
7fc9d69f 199
abc06822 200--resolve-git-dir <path>::
0859c969
TA
201 Check if <path> is a valid repository or a gitfile that
202 points at a valid repository, and print the location of the
203 repository. If <path> is a gitfile then the resolved path
204 to the real repository is printed.
205
7fc9d69f 206
5a8f3117 207include::revisions.txt[]
be4c7014 208
21d47835
PH
209PARSEOPT
210--------
211
0b444cdb 212In `--parseopt` mode, 'git rev-parse' helps massaging options to bring to shell
21d47835
PH
213scripts the same facilities C builtins have. It works as an option normalizer
214(e.g. splits single switches aggregate values), a bit like `getopt(1)` does.
215
216It takes on the standard input the specification of the options to parse and
ac2e1e63 217understand, and echoes on the standard output a string suitable for `sh(1)` `eval`
21d47835
PH
218to replace the arguments with normalized ones. In case of error, it outputs
219usage on the standard error stream, and exits with code 129.
220
ac2e1e63
TR
221Note: Make sure you quote the result when passing it to `eval`. See
222below for an example.
223
21d47835
PH
224Input Format
225~~~~~~~~~~~~
226
0b444cdb 227'git rev-parse --parseopt' input format is fully text based. It has two parts,
21d47835
PH
228separated by a line that contains only `--`. The lines before the separator
229(should be more than one) are used for the usage.
230The lines after the separator describe the options.
231
232Each line of options has this format:
233
234------------
ff962a3f 235<opt_spec><flags>* SP+ help LF
21d47835
PH
236------------
237
238`<opt_spec>`::
239 its format is the short option character, then the long option name
240 separated by a comma. Both parts are not required, though at least one
241 is necessary. `h,help`, `dry-run` and `f` are all three correct
242 `<opt_spec>`.
243
ff962a3f
PH
244`<flags>`::
245 `<flags>` are of `*`, `=`, `?` or `!`.
246 * Use `=` if the option takes an argument.
247
248 * Use `?` to mean that the option is optional (though its use is discouraged).
249
250 * Use `*` to mean that this option should not be listed in the usage
251 generated for the `-h` argument. It's shown for `--help-all` as
a5af0e2c 252 documented in linkgit:gitcli[7].
ff962a3f
PH
253
254 * Use `!` to not make the corresponding negated long option available.
21d47835
PH
255
256The remainder of the line, after stripping the spaces, is used
257as the help associated to the option.
258
259Blank lines are ignored, and lines that don't match this specification are used
260as option group headers (start the line with a space to create such
261lines on purpose).
262
263Example
264~~~~~~~
265
266------------
267OPTS_SPEC="\
268some-command [options] <args>...
269
270some-command does foo and bar!
271--
272h,help show the help
273
274foo some nifty option --foo
275bar= some cool option --bar with an argument
276
277 An option group Header
278C? option C with an optional argument"
279
ac2e1e63 280eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
21d47835
PH
281------------
282
50325377
CC
283SQ-QUOTE
284--------
285
0b444cdb 286In `--sq-quote` mode, 'git rev-parse' echoes on the standard output a
50325377
CC
287single line suitable for `sh(1)` `eval`. This line is made by
288normalizing the arguments following `--sq-quote`. Nothing other than
289quoting the arguments is done.
290
291If you want command input to still be interpreted as usual by
0b444cdb 292'git rev-parse' before the output is shell quoted, see the `--sq`
50325377
CC
293option.
294
295Example
296~~~~~~~
297
298------------
299$ cat >your-git-script.sh <<\EOF
300#!/bin/sh
301args=$(git rev-parse --sq-quote "$@") # quote user-supplied arguments
302command="git frotz -n24 $args" # and use it inside a handcrafted
303 # command line
304eval "$command"
305EOF
306
307$ sh your-git-script.sh "a b'c"
308------------
309
824b5dc2
CC
310EXAMPLES
311--------
312
313* Print the object name of the current commit:
314+
315------------
316$ git rev-parse --verify HEAD
317------------
318
319* Print the commit object name from the revision in the $REV shell variable:
320+
321------------
2db60670 322$ git rev-parse --verify $REV^{commit}
824b5dc2
CC
323------------
324+
325This will error out if $REV is empty or not a valid revision.
326
2db60670 327* Similar to above:
824b5dc2
CC
328+
329------------
330$ git rev-parse --default master --verify $REV
331------------
332+
333but if $REV is empty, the commit object name from master will be printed.
334
7fc9d69f
JH
335GIT
336---
9e1f0a85 337Part of the linkgit:git[1] suite