interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / git-rev-parse.adoc

528 lines · 17349 bytes Raw Blame History
1git-rev-parse(1)
2================
3
4NAME
5----
6git-rev-parse - Pick out and massage parameters
7
8
9SYNOPSIS
10--------
11[verse]
12'git rev-parse' [<options>] <arg>...
13
14DESCRIPTION
15-----------
16
17Many Git porcelainish commands take a mixture of flags
18(i.e. parameters that begin with a dash '-') and parameters
19meant for the underlying 'git rev-list' command they use internally
20and flags and parameters for the other commands they use
21downstream of 'git rev-list'. The primary purpose of this command
22is to allow calling programs to distinguish between them. There are
23a few other operation modes that have nothing to do with the above
24"help parse command line options".
25
26Unless otherwise specified, most of the options and operation modes
27require you to run this command inside a git repository or a working
28tree that is under the control of a git repository, and will give you
29a fatal error otherwise.
30
31
32OPTIONS
33-------
34
35Operation Modes
36~~~~~~~~~~~~~~~
37
38Each of these options must appear first on the command line.
39
40--parseopt::
41 Use 'git rev-parse' in option parsing mode
42 (see <<PARSEOPT,PARSEOPT>> section below).
43 The command in this mode can be used outside a repository or
44 a working tree controlled by a repository.
45
46--sq-quote::
47 Use 'git rev-parse' in shell quoting mode (see <<SQ_QUOTE,SQ-QUOTE>>
48 section below). In contrast to the `--sq` option below, this
49 mode only does quoting. Nothing else is done to command input.
50 The command in this mode can be used outside a repository or
51 a working tree controlled by a repository.
52
53Options for --parseopt
54~~~~~~~~~~~~~~~~~~~~~~
55
56--keep-dashdash::
57 Only meaningful in `--parseopt` mode. Tells the option parser to echo
58 out the first `--` met instead of skipping it.
59
60--stop-at-non-option::
61 Only meaningful in `--parseopt` mode. Lets the option parser stop at
62 the first non-option argument. This can be used to parse sub-commands
63 that take options themselves.
64
65--stuck-long::
66 Only meaningful in `--parseopt` mode. Output the options in their
67 long form if available, and with their arguments stuck.
68
69Options for Filtering
70~~~~~~~~~~~~~~~~~~~~~
71
72--revs-only::
73 Do not output flags and parameters not meant for
74 'git rev-list' command.
75
76--no-revs::
77 Do not output flags and parameters meant for
78 'git rev-list' command.
79
80--flags::
81 Do not output non-flag parameters.
82
83--no-flags::
84 Do not output flag parameters.
85
86Options for Output
87~~~~~~~~~~~~~~~~~~
88
89--default <arg>::
90 If there is no parameter given by the user, use `<arg>`
91 instead.
92
93--prefix <arg>::
94 Behave as if 'git rev-parse' was invoked from the `<arg>`
95 subdirectory of the working tree. Any relative filenames are
96 resolved as if they are prefixed by `<arg>` and will be printed
97 in that form.
98+
99This can be used to convert arguments to a command run in a subdirectory
100so that they can still be used after moving to the top-level of the
101repository. For example:
102+
103----
104prefix=$(git rev-parse --show-prefix)
105cd "$(git rev-parse --show-toplevel)"
106# rev-parse provides the -- needed for 'set'
107eval "set $(git rev-parse --sq --prefix "$prefix" -- "$@")"
108----
109
110--verify::
111 Verify that exactly one parameter is provided, and that it
112 can be turned into a raw 20-byte SHA-1 that can be used to
113 access the object database. If so, emit it to the standard
114 output; otherwise, error out.
115+
116If you want to make sure that the output actually names an object in
117your object database and/or can be used as a specific type of object
118you require, you can add the `^{type}` peeling operator to the parameter.
119For example, `git rev-parse "$VAR^{commit}"` will make sure `$VAR`
120names an existing object that is a commit-ish (i.e. a commit, or an
121annotated tag that points at a commit). To make sure that `$VAR`
122names an existing object of any type, `git rev-parse "$VAR^{object}"`
123can be used.
124+
125Note that if you are verifying a name from an untrusted source, it is
126wise to use `--end-of-options` so that the name argument is not mistaken
127for another option.
128
129-q::
130--quiet::
131 Only meaningful in `--verify` mode. Do not output an error
132 message if the first argument is not a valid object name;
133 instead exit with non-zero status silently.
134 SHA-1s for valid object names are printed to stdout on success.
135
136--sq::
137 Usually the output is made one line per flag and
138 parameter. This option makes output a single line,
139 properly quoted for consumption by shell. Useful when
140 you expect your parameter to contain whitespaces and
141 newlines (e.g. when using pickaxe `-S` with
142 'git diff-{asterisk}'). In contrast to the `--sq-quote` option,
143 the command input is still interpreted as usual.
144
145--short[=<length>]::
146 Same as `--verify` but shortens the object name to a unique
147 prefix with at least `length` characters. The minimum length
148 is 4, the default is the effective value of the `core.abbrev`
149 configuration variable (see linkgit:git-config[1]).
150
151--not::
152 When showing object names, prefix them with '{caret}' and
153 strip '{caret}' prefix from the object names that already have
154 one.
155
156--abbrev-ref[=(strict|loose)]::
157 A non-ambiguous short name of the objects name.
158 The option core.warnAmbiguousRefs is used to select the strict
159 abbreviation mode.
160
161--symbolic::
162 Usually the object names are output in SHA-1 form (with
163 possible '{caret}' prefix); this option makes them output in a
164 form as close to the original input as possible.
165
166--symbolic-full-name::
167 This is similar to --symbolic, but it omits input that
168 are not refs (i.e. branch or tag names; or more
169 explicitly disambiguating "heads/master" form, when you
170 want to name the "master" branch when there is an
171 unfortunately named tag "master"), and shows them as full
172 refnames (e.g. "refs/heads/master").
173
174--output-object-format=(sha1|sha256|storage)::
175
176 Allow oids to be input from any object format that the current
177 repository supports.
178+
179Specifying "sha1" translates if necessary and returns a sha1 oid.
180+
181Specifying "sha256" translates if necessary and returns a sha256 oid.
182+
183Specifying "storage" translates if necessary and returns an oid in
184encoded in the storage hash algorithm.
185
186Options for Objects
187~~~~~~~~~~~~~~~~~~~
188
189--all::
190 Show all refs found in `refs/`.
191
192--branches[=<pattern>]::
193--tags[=<pattern>]::
194--remotes[=<pattern>]::
195 Show all branches, tags, or remote-tracking branches,
196 respectively (i.e., refs found in `refs/heads`,
197 `refs/tags`, or `refs/remotes`, respectively).
198+
199If a `pattern` is given, only refs matching the given shell glob are
200shown. If the pattern does not contain a globbing character (`?`,
201`*`, or `[`), it is turned into a prefix match by appending `/*`.
202
203--glob=<pattern>::
204 Show all refs matching the shell glob pattern `pattern`. If
205 the pattern does not start with `refs/`, this is automatically
206 prepended. If the pattern does not contain a globbing
207 character (`?`, `*`, or `[`), it is turned into a prefix
208 match by appending `/*`.
209
210--exclude=<glob-pattern>::
211 Do not include refs matching '<glob-pattern>' that the next `--all`,
212 `--branches`, `--tags`, `--remotes`, or `--glob` would otherwise
213 consider. Repetitions of this option accumulate exclusion patterns
214 up to the next `--all`, `--branches`, `--tags`, `--remotes`, or
215 `--glob` option (other options or arguments do not clear
216 accumulated patterns).
217+
218The patterns given should not begin with `refs/heads`, `refs/tags`, or
219`refs/remotes` when applied to `--branches`, `--tags`, or `--remotes`,
220respectively, and they must begin with `refs/` when applied to `--glob`
221or `--all`. If a trailing '/{asterisk}' is intended, it must be given
222explicitly.
223
224--exclude-hidden=(fetch|receive|uploadpack)::
225 Do not include refs that would be hidden by `git-fetch`,
226 `git-receive-pack` or `git-upload-pack` by consulting the appropriate
227 `fetch.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs`
228 configuration along with `transfer.hideRefs` (see
229 linkgit:git-config[1]). This option affects the next pseudo-ref option
230 `--all` or `--glob` and is cleared after processing them.
231
232--disambiguate=<prefix>::
233 Show every object whose name begins with the given prefix.
234 The <prefix> must be at least 4 hexadecimal digits long to
235 avoid listing each and every object in the repository by
236 mistake.
237
238Options for Files
239~~~~~~~~~~~~~~~~~
240
241--local-env-vars::
242 List the GIT_* environment variables that are local to the
243 repository (e.g. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR).
244 Only the names of the variables are listed, not their value,
245 even if they are set.
246
247--path-format=(absolute|relative)::
248 Controls the behavior of certain other options. If specified as absolute, the
249 paths printed by those options will be absolute and canonical. If specified as
250 relative, the paths will be relative to the current working directory if that
251 is possible. The default is option specific.
252+
253This option may be specified multiple times and affects only the arguments that
254follow it on the command line, either to the end of the command line or the next
255instance of this option.
256
257The following options are modified by `--path-format`:
258
259--git-dir::
260 Show `$GIT_DIR` if defined. Otherwise show the path to
261 the .git directory. The path shown, when relative, is
262 relative to the current working directory.
263+
264If `$GIT_DIR` is not defined and the current directory
265is not detected to lie in a Git repository or work tree
266print a message to stderr and exit with nonzero status.
267
268--git-common-dir::
269 Show `$GIT_COMMON_DIR` if defined, else `$GIT_DIR`.
270
271--resolve-git-dir <path>::
272 Check if <path> is a valid repository or a gitfile that
273 points at a valid repository, and print the location of the
274 repository. If <path> is a gitfile then the resolved path
275 to the real repository is printed.
276
277--git-path <path>::
278 Resolve "$GIT_DIR/<path>" and takes other path relocation
279 variables such as $GIT_OBJECT_DIRECTORY,
280 $GIT_INDEX_FILE... into account. For example, if
281 $GIT_OBJECT_DIRECTORY is set to /foo/bar then "git rev-parse
282 --git-path objects/abc" returns /foo/bar/abc.
283
284--show-toplevel::
285 Show the (by default, absolute) path of the top-level directory
286 of the working tree. If there is no working tree, report an error.
287
288--show-superproject-working-tree::
289 Show the absolute path of the root of the superproject's
290 working tree (if exists) that uses the current repository as
291 its submodule. Outputs nothing if the current repository is
292 not used as a submodule by any project.
293
294--shared-index-path::
295 Show the path to the shared index file in split index mode, or
296 empty if not in split-index mode.
297
298The following options are unaffected by `--path-format`:
299
300--absolute-git-dir::
301 Like `--git-dir`, but its output is always the canonicalized
302 absolute path.
303
304--is-inside-git-dir::
305 When the current working directory is below the repository
306 directory print "true", otherwise "false".
307
308--is-inside-work-tree::
309 When the current working directory is inside the work tree of the
310 repository print "true", otherwise "false".
311
312--is-bare-repository::
313 When the repository is bare print "true", otherwise "false".
314
315--is-shallow-repository::
316 When the repository is shallow print "true", otherwise "false".
317
318--show-cdup::
319 When the command is invoked from a subdirectory, show the
320 path of the top-level directory relative to the current
321 directory (typically a sequence of "../", or an empty string).
322
323--show-prefix::
324 When the command is invoked from a subdirectory, show the
325 path of the current directory relative to the top-level
326 directory.
327
328--show-object-format[=(storage|input|output|compat)]::
329 Show the object format (hash algorithm) used for the repository for storage
330 inside the `.git` directory, input, output, or compatibility. For input,
331 multiple algorithms may be printed, space-separated. If `compat` is
332 requested and no compatibility algorithm is enabled, prints an empty line. If
333 not specified, the default is "storage".
334
335--show-ref-storage-format::
336 Show the reference storage format used for the repository.
337
338--show-ref-format::
339 Deprecated alias of `--show-ref-storage-format`.
340
341--show-object-storage-format::
342 Show the object storage format used for the repository. Prints the
343 value of `extensions.objectStorage`, or `files` when the extension is
344 not set.
345
346
347Other Options
348~~~~~~~~~~~~~
349
350--since=<datestring>::
351--after=<datestring>::
352 Parse the date string, and output the corresponding
353 --max-age= parameter for 'git rev-list'.
354
355--until=<datestring>::
356--before=<datestring>::
357 Parse the date string, and output the corresponding
358 --min-age= parameter for 'git rev-list'.
359
360<arg>...::
361 Flags and parameters to be parsed.
362
363
364include::revisions.adoc[]
365
366[[PARSEOPT]]
367PARSEOPT
368--------
369
370In `--parseopt` mode, 'git rev-parse' helps massaging options to bring to shell
371scripts the same facilities C builtins have. It works as an option normalizer
372(e.g. splits single switches aggregate values), a bit like `getopt(1)` does.
373
374It takes on the standard input the specification of the options to parse and
375understand, and echoes on the standard output a string suitable for `sh(1)` `eval`
376to replace the arguments with normalized ones. In case of error, it outputs
377usage on the standard error stream, and exits with code 129.
378
379Note: Make sure you quote the result when passing it to `eval`. See
380below for an example.
381
382Input Format
383~~~~~~~~~~~~
384
385'git rev-parse --parseopt' input format is fully text based. It has two parts,
386separated by a line that contains only `--`. The lines before the separator
387(should be one or more) are used for the usage.
388The lines after the separator describe the options.
389
390Each line of options has this format:
391
392------------
393<opt-spec><flags>*<arg-hint>? SP+ help LF
394------------
395
396`<opt-spec>`::
397 its format is the short option character, then the long option name
398 separated by a comma. Both parts are not required, though at least one
399 is necessary. May not contain any of the `<flags>` characters.
400 `h,help`, `dry-run` and `f` are examples of correct `<opt-spec>`.
401
402`<flags>`::
403 `<flags>` are of `*`, `=`, `?` or `!`.
404 * Use `=` if the option takes an argument.
405
406 * Use `?` to mean that the option takes an optional argument. You
407 probably want to use the `--stuck-long` mode to be able to
408 unambiguously parse the optional argument.
409
410 * Use `*` to mean that this option should not be listed in the usage
411 generated for the `-h` argument. It's shown for `--help-all` as
412 documented in linkgit:gitcli[7].
413
414 * Use `!` to not make the corresponding negated long option available.
415
416`<arg-hint>`::
417 `<arg-hint>`, if specified, is used as a name of the argument in the
418 help output, for options that take arguments. `<arg-hint>` is
419 terminated by the first whitespace. It is customary to use a
420 dash to separate words in a multi-word argument hint.
421
422The remainder of the line, after stripping the spaces, is used
423as the help associated with the option.
424
425Blank lines are ignored, and lines that don't match this specification are used
426as option group headers (start the line with a space to create such
427lines on purpose).
428
429Example
430~~~~~~~
431
432------------
433OPTS_SPEC="\
434some-command [<options>] <args>...
435
436some-command does foo and bar!
437--
438h,help! show the help
439
440foo some nifty option --foo
441bar= some cool option --bar with an argument
442baz=arg another cool option --baz with a named argument
443qux?path qux may take a path argument but has meaning by itself
444
445 An option group Header
446C? option C with an optional argument"
447
448eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
449------------
450
451
452Usage text
453~~~~~~~~~~
454
455When `"$@"` is `-h` or `--help` in the above example, the following
456usage text would be shown:
457
458------------
459usage: some-command [<options>] <args>...
460
461 some-command does foo and bar!
462
463 -h, --help show the help
464 --[no-]foo some nifty option --foo
465 --[no-]bar ... some cool option --bar with an argument
466 --[no-]baz <arg> another cool option --baz with a named argument
467 --[no-]qux[=<path>] qux may take a path argument but has meaning by itself
468
469An option group Header
470 -C[...] option C with an optional argument
471------------
472
473[[SQ_QUOTE]]
474SQ-QUOTE
475--------
476
477In `--sq-quote` mode, 'git rev-parse' echoes on the standard output a
478single line suitable for `sh(1)` `eval`. This line is made by
479normalizing the arguments following `--sq-quote`. Nothing other than
480quoting the arguments is done.
481
482If you want command input to still be interpreted as usual by
483'git rev-parse' before the output is shell quoted, see the `--sq`
484option.
485
486Example
487~~~~~~~
488
489------------
490$ cat >your-git-script.sh <<\EOF
491#!/bin/sh
492args=$(git rev-parse --sq-quote "$@") # quote user-supplied arguments
493command="git frotz -n24 $args" # and use it inside a handcrafted
494 # command line
495eval "$command"
496EOF
497
498$ sh your-git-script.sh "a b'c"
499------------
500
501EXAMPLES
502--------
503
504* Print the object name of the current commit:
505+
506------------
507$ git rev-parse --verify HEAD
508------------
509
510* Print the commit object name from the revision in the $REV shell variable:
511+
512------------
513$ git rev-parse --verify --end-of-options $REV^{commit}
514------------
515+
516This will error out if $REV is empty or not a valid revision.
517
518* Similar to above:
519+
520------------
521$ git rev-parse --default master --verify --end-of-options $REV
522------------
523+
524but if $REV is empty, the commit object name from master will be printed.
525
526GIT
527---
528Part of the linkgit:git[1] suite