Autogenerated manpages for v2.45.2-659-gdaed0
[git-manpages.git] / man1 / git-rev-parse.1
blob156d769097d5847edffba35595a3f64da9a1af03
1 '\" t
2 .\"     Title: git-rev-parse
3 .\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2024-06-27
6 .\"    Manual: Git Manual
7 .\"    Source: Git 2.45.2.659.gdaed0c68e9
8 .\"  Language: English
9 .\"
10 .TH "GIT\-REV\-PARSE" "1" "2024\-06\-27" "Git 2\&.45\&.2\&.659\&.gdaed0c" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 git-rev-parse \- Pick out and massage parameters
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 \fIgit rev\-parse\fR [<options>] <arg>\&...
36 .fi
37 .sp
38 .SH "DESCRIPTION"
39 .sp
40 Many Git porcelainish commands take a mixture of flags (i\&.e\&. parameters that begin with a dash \fI\-\fR) and parameters meant for the underlying \fIgit rev\-list\fR command they use internally and flags and parameters for the other commands they use downstream of \fIgit rev\-list\fR\&. The primary purpose of this command is to allow calling programs to distinguish between them\&. There are a few other operation modes that have nothing to do with the above "help parse command line options"\&.
41 .sp
42 Unless otherwise specified, most of the options and operation modes require you to run this command inside a git repository or a working tree that is under the control of a git repository, and will give you a fatal error otherwise\&.
43 .SH "OPTIONS"
44 .SS "Operation Modes"
45 .sp
46 Each of these options must appear first on the command line\&.
47 .PP
48 \-\-parseopt
49 .RS 4
50 Use
51 \fIgit rev\-parse\fR
52 in option parsing mode (see PARSEOPT section below)\&. The command in this mode can be used outside a repository or a working tree controlled by a repository\&.
53 .RE
54 .PP
55 \-\-sq\-quote
56 .RS 4
57 Use
58 \fIgit rev\-parse\fR
59 in shell quoting mode (see SQ\-QUOTE section below)\&. In contrast to the
60 \fB\-\-sq\fR
61 option below, this mode only does quoting\&. Nothing else is done to command input\&. The command in this mode can be used outside a repository or a working tree controlled by a repository\&.
62 .RE
63 .SS "Options for \-\-parseopt"
64 .PP
65 \-\-keep\-dashdash
66 .RS 4
67 Only meaningful in
68 \fB\-\-parseopt\fR
69 mode\&. Tells the option parser to echo out the first
70 \fB\-\-\fR
71 met instead of skipping it\&.
72 .RE
73 .PP
74 \-\-stop\-at\-non\-option
75 .RS 4
76 Only meaningful in
77 \fB\-\-parseopt\fR
78 mode\&. Lets the option parser stop at the first non\-option argument\&. This can be used to parse sub\-commands that take options themselves\&.
79 .RE
80 .PP
81 \-\-stuck\-long
82 .RS 4
83 Only meaningful in
84 \fB\-\-parseopt\fR
85 mode\&. Output the options in their long form if available, and with their arguments stuck\&.
86 .RE
87 .SS "Options for Filtering"
88 .PP
89 \-\-revs\-only
90 .RS 4
91 Do not output flags and parameters not meant for
92 \fIgit rev\-list\fR
93 command\&.
94 .RE
95 .PP
96 \-\-no\-revs
97 .RS 4
98 Do not output flags and parameters meant for
99 \fIgit rev\-list\fR
100 command\&.
103 \-\-flags
104 .RS 4
105 Do not output non\-flag parameters\&.
108 \-\-no\-flags
109 .RS 4
110 Do not output flag parameters\&.
112 .SS "Options for Output"
114 \-\-default <arg>
115 .RS 4
116 If there is no parameter given by the user, use
117 \fB<arg>\fR
118 instead\&.
121 \-\-prefix <arg>
122 .RS 4
123 Behave as if
124 \fIgit rev\-parse\fR
125 was invoked from the
126 \fB<arg>\fR
127 subdirectory of the working tree\&. Any relative filenames are resolved as if they are prefixed by
128 \fB<arg>\fR
129 and will be printed in that form\&.
131 This can be used to convert arguments to a command run in a subdirectory so that they can still be used after moving to the top\-level of the repository\&. For example:
133 .if n \{\
134 .RS 4
137 prefix=$(git rev\-parse \-\-show\-prefix)
138 cd "$(git rev\-parse \-\-show\-toplevel)"
139 # rev\-parse provides the \-\- needed for \*(Aqset\*(Aq
140 eval "set $(git rev\-parse \-\-sq \-\-prefix "$prefix" \-\- "$@")"
142 .if n \{\
148 \-\-verify
149 .RS 4
150 Verify that exactly one parameter is provided, and that it can be turned into a raw 20\-byte SHA\-1 that can be used to access the object database\&. If so, emit it to the standard output; otherwise, error out\&.
152 If you want to make sure that the output actually names an object in your object database and/or can be used as a specific type of object you require, you can add the
153 \fB^{type}\fR
154 peeling operator to the parameter\&. For example,
155 \fBgit rev\-parse "$VAR^{commit}"\fR
156 will make sure
157 \fB$VAR\fR
158 names an existing object that is a commit\-ish (i\&.e\&. a commit, or an annotated tag that points at a commit)\&. To make sure that
159 \fB$VAR\fR
160 names an existing object of any type,
161 \fBgit rev\-parse "$VAR^{object}"\fR
162 can be used\&.
164 Note that if you are verifying a name from an untrusted source, it is wise to use
165 \fB\-\-end\-of\-options\fR
166 so that the name argument is not mistaken for another option\&.
169 \-q, \-\-quiet
170 .RS 4
171 Only meaningful in
172 \fB\-\-verify\fR
173 mode\&. Do not output an error message if the first argument is not a valid object name; instead exit with non\-zero status silently\&. SHA\-1s for valid object names are printed to stdout on success\&.
176 \-\-sq
177 .RS 4
178 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
179 \fB\-S\fR
180 with
181 \fIgit diff\-*\fR)\&. In contrast to the
182 \fB\-\-sq\-quote\fR
183 option, the command input is still interpreted as usual\&.
186 \-\-short[=<length>]
187 .RS 4
188 Same as
189 \fB\-\-verify\fR
190 but shortens the object name to a unique prefix with at least
191 \fBlength\fR
192 characters\&. The minimum length is 4, the default is the effective value of the
193 \fBcore\&.abbrev\fR
194 configuration variable (see
195 \fBgit-config\fR(1))\&.
198 \-\-not
199 .RS 4
200 When showing object names, prefix them with
201 \fI^\fR
202 and strip
203 \fI^\fR
204 prefix from the object names that already have one\&.
207 \-\-abbrev\-ref[=(strict|loose)]
208 .RS 4
209 A non\-ambiguous short name of the objects name\&. The option core\&.warnAmbiguousRefs is used to select the strict abbreviation mode\&.
212 \-\-symbolic
213 .RS 4
214 Usually the object names are output in SHA\-1 form (with possible
215 \fI^\fR
216 prefix); this option makes them output in a form as close to the original input as possible\&.
219 \-\-symbolic\-full\-name
220 .RS 4
221 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 shows them as full refnames (e\&.g\&. "refs/heads/master")\&.
224 \-\-output\-object\-format=(sha1|sha256|storage)
225 .RS 4
226 Allow oids to be input from any object format that the current repository supports\&.
228 .if n \{\
229 .RS 4
232 Specifying "sha1" translates if necessary and returns a sha1 oid\&.
234 .if n \{\
238 .if n \{\
239 .RS 4
242 Specifying "sha256" translates if necessary and returns a sha256 oid\&.
244 .if n \{\
248 .if n \{\
249 .RS 4
252 Specifying "storage" translates if necessary and returns an oid in
253 encoded in the storage hash algorithm\&.
255 .if n \{\
259 .SS "Options for Objects"
261 \-\-all
262 .RS 4
263 Show all refs found in
264 \fBrefs/\fR\&.
267 \-\-branches[=<pattern>], \-\-tags[=<pattern>], \-\-remotes[=<pattern>]
268 .RS 4
269 Show all branches, tags, or remote\-tracking branches, respectively (i\&.e\&., refs found in
270 \fBrefs/heads\fR,
271 \fBrefs/tags\fR, or
272 \fBrefs/remotes\fR, respectively)\&.
274 If a
275 \fBpattern\fR
276 is given, only refs matching the given shell glob are shown\&. If the pattern does not contain a globbing character (\fB?\fR,
277 \fB*\fR, or
278 \fB[\fR), it is turned into a prefix match by appending
279 \fB/*\fR\&.
282 \-\-glob=<pattern>
283 .RS 4
284 Show all refs matching the shell glob pattern
285 \fBpattern\fR\&. If the pattern does not start with
286 \fBrefs/\fR, this is automatically prepended\&. If the pattern does not contain a globbing character (\fB?\fR,
287 \fB*\fR, or
288 \fB[\fR), it is turned into a prefix match by appending
289 \fB/*\fR\&.
292 \-\-exclude=<glob\-pattern>
293 .RS 4
294 Do not include refs matching
295 \fI<glob\-pattern>\fR
296 that the next
297 \fB\-\-all\fR,
298 \fB\-\-branches\fR,
299 \fB\-\-tags\fR,
300 \fB\-\-remotes\fR, or
301 \fB\-\-glob\fR
302 would otherwise consider\&. Repetitions of this option accumulate exclusion patterns up to the next
303 \fB\-\-all\fR,
304 \fB\-\-branches\fR,
305 \fB\-\-tags\fR,
306 \fB\-\-remotes\fR, or
307 \fB\-\-glob\fR
308 option (other options or arguments do not clear accumulated patterns)\&.
310 The patterns given should not begin with
311 \fBrefs/heads\fR,
312 \fBrefs/tags\fR, or
313 \fBrefs/remotes\fR
314 when applied to
315 \fB\-\-branches\fR,
316 \fB\-\-tags\fR, or
317 \fB\-\-remotes\fR, respectively, and they must begin with
318 \fBrefs/\fR
319 when applied to
320 \fB\-\-glob\fR
322 \fB\-\-all\fR\&. If a trailing
323 \fI/*\fR
324 is intended, it must be given explicitly\&.
327 \-\-exclude\-hidden=(fetch|receive|uploadpack)
328 .RS 4
329 Do not include refs that would be hidden by
330 \fBgit\-fetch\fR,
331 \fBgit\-receive\-pack\fR
333 \fBgit\-upload\-pack\fR
334 by consulting the appropriate
335 \fBfetch\&.hideRefs\fR,
336 \fBreceive\&.hideRefs\fR
338 \fBuploadpack\&.hideRefs\fR
339 configuration along with
340 \fBtransfer\&.hideRefs\fR
341 (see
342 \fBgit-config\fR(1))\&. This option affects the next pseudo\-ref option
343 \fB\-\-all\fR
345 \fB\-\-glob\fR
346 and is cleared after processing them\&.
349 \-\-disambiguate=<prefix>
350 .RS 4
351 Show every object whose name begins with the given prefix\&. The <prefix> must be at least 4 hexadecimal digits long to avoid listing each and every object in the repository by mistake\&.
353 .SS "Options for Files"
355 \-\-local\-env\-vars
356 .RS 4
357 List the GIT_* environment variables that are local to the repository (e\&.g\&. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR)\&. Only the names of the variables are listed, not their value, even if they are set\&.
360 \-\-path\-format=(absolute|relative)
361 .RS 4
362 Controls the behavior of certain other options\&. If specified as absolute, the paths printed by those options will be absolute and canonical\&. If specified as relative, the paths will be relative to the current working directory if that is possible\&. The default is option specific\&.
364 This option may be specified multiple times and affects only the arguments that follow it on the command line, either to the end of the command line or the next instance of this option\&.
367 The following options are modified by \fB\-\-path\-format\fR:
369 \-\-git\-dir
370 .RS 4
371 Show
372 \fB$GIT_DIR\fR
373 if defined\&. Otherwise show the path to the \&.git directory\&. The path shown, when relative, is relative to the current working directory\&.
376 \fB$GIT_DIR\fR
377 is not defined and the current directory is not detected to lie in a Git repository or work tree print a message to stderr and exit with nonzero status\&.
380 \-\-git\-common\-dir
381 .RS 4
382 Show
383 \fB$GIT_COMMON_DIR\fR
384 if defined, else
385 \fB$GIT_DIR\fR\&.
388 \-\-resolve\-git\-dir <path>
389 .RS 4
390 Check if <path> is a valid repository or a gitfile that points at a valid repository, and print the location of the repository\&. If <path> is a gitfile then the resolved path to the real repository is printed\&.
393 \-\-git\-path <path>
394 .RS 4
395 Resolve "$GIT_DIR/<path>" and takes other path relocation variables such as $GIT_OBJECT_DIRECTORY, $GIT_INDEX_FILE\&... into account\&. For example, if $GIT_OBJECT_DIRECTORY is set to /foo/bar then "git rev\-parse \-\-git\-path objects/abc" returns /foo/bar/abc\&.
398 \-\-show\-toplevel
399 .RS 4
400 Show the (by default, absolute) path of the top\-level directory of the working tree\&. If there is no working tree, report an error\&.
403 \-\-show\-superproject\-working\-tree
404 .RS 4
405 Show the absolute path of the root of the superproject\(cqs working tree (if exists) that uses the current repository as its submodule\&. Outputs nothing if the current repository is not used as a submodule by any project\&.
408 \-\-shared\-index\-path
409 .RS 4
410 Show the path to the shared index file in split index mode, or empty if not in split\-index mode\&.
413 The following options are unaffected by \fB\-\-path\-format\fR:
415 \-\-absolute\-git\-dir
416 .RS 4
417 Like
418 \fB\-\-git\-dir\fR, but its output is always the canonicalized absolute path\&.
421 \-\-is\-inside\-git\-dir
422 .RS 4
423 When the current working directory is below the repository directory print "true", otherwise "false"\&.
426 \-\-is\-inside\-work\-tree
427 .RS 4
428 When the current working directory is inside the work tree of the repository print "true", otherwise "false"\&.
431 \-\-is\-bare\-repository
432 .RS 4
433 When the repository is bare print "true", otherwise "false"\&.
436 \-\-is\-shallow\-repository
437 .RS 4
438 When the repository is shallow print "true", otherwise "false"\&.
441 \-\-show\-cdup
442 .RS 4
443 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)\&.
446 \-\-show\-prefix
447 .RS 4
448 When the command is invoked from a subdirectory, show the path of the current directory relative to the top\-level directory\&.
451 \-\-show\-object\-format[=(storage|input|output)]
452 .RS 4
453 Show the object format (hash algorithm) used for the repository for storage inside the
454 \fB\&.git\fR
455 directory, input, or output\&. For input, multiple algorithms may be printed, space\-separated\&. If not specified, the default is "storage"\&.
458 \-\-show\-ref\-format
459 .RS 4
460 Show the reference storage format used for the repository\&.
462 .SS "Other Options"
464 \-\-since=<datestring>, \-\-after=<datestring>
465 .RS 4
466 Parse the date string, and output the corresponding \-\-max\-age= parameter for
467 \fIgit rev\-list\fR\&.
470 \-\-until=<datestring>, \-\-before=<datestring>
471 .RS 4
472 Parse the date string, and output the corresponding \-\-min\-age= parameter for
473 \fIgit rev\-list\fR\&.
476 <arg>\&...
477 .RS 4
478 Flags and parameters to be parsed\&.
480 .SH "SPECIFYING REVISIONS"
482 A revision parameter \fI<rev>\fR typically, but not necessarily, names a commit object\&. It uses what is called an \fIextended SHA\-1\fR syntax\&. Here are various ways to spell object names\&. The ones listed near the end of this list name trees and blobs contained in a commit\&.
483 .if n \{\
486 .RS 4
487 .it 1 an-trap
488 .nr an-no-space-flag 1
489 .nr an-break-flag 1
491 .ps +1
492 \fBNote\fR
493 .ps -1
496 This document shows the "raw" syntax as seen by git\&. The shell and other UIs might require additional quoting to protect special characters and to avoid word splitting\&.
497 .sp .5v
500 \fI<sha1>\fR, e\&.g\&. \fIdae86e1950b1277e545cee180551750029cfe735\fR, \fIdae86e\fR
501 .RS 4
502 The full SHA\-1 object name (40\-byte hexadecimal string), or a leading substring that is unique within the repository\&. E\&.g\&. dae86e1950b1277e545cee180551750029cfe735 and dae86e both name the same commit object if there is no other object in your repository whose object name starts with dae86e\&.
505 \fI<describeOutput>\fR, e\&.g\&. \fIv1\&.7\&.4\&.2\-679\-g3bee7fb\fR
506 .RS 4
507 Output from
508 \fBgit describe\fR; i\&.e\&. a closest tag, optionally followed by a dash and a number of commits, followed by a dash, a
509 \fIg\fR, and an abbreviated object name\&.
512 \fI<refname>\fR, e\&.g\&. \fImaster\fR, \fIheads/master\fR, \fIrefs/heads/master\fR
513 .RS 4
514 A symbolic ref name\&. E\&.g\&.
515 \fImaster\fR
516 typically means the commit object referenced by
517 \fIrefs/heads/master\fR\&. If you happen to have both
518 \fIheads/master\fR
520 \fItags/master\fR, you can explicitly say
521 \fIheads/master\fR
522 to tell Git which one you mean\&. When ambiguous, a
523 \fI<refname>\fR
524 is disambiguated by taking the first match in the following rules:
526 .RS 4
527 .ie n \{\
528 \h'-04' 1.\h'+01'\c
530 .el \{\
531 .sp -1
532 .IP "  1." 4.2
535 \fI$GIT_DIR/<refname>\fR
536 exists, that is what you mean (this is usually useful only for
537 \fBHEAD\fR,
538 \fBFETCH_HEAD\fR,
539 \fBORIG_HEAD\fR,
540 \fBMERGE_HEAD\fR,
541 \fBREBASE_HEAD\fR,
542 \fBREVERT_HEAD\fR,
543 \fBCHERRY_PICK_HEAD\fR,
544 \fBBISECT_HEAD\fR
546 \fBAUTO_MERGE\fR);
549 .RS 4
550 .ie n \{\
551 \h'-04' 2.\h'+01'\c
553 .el \{\
554 .sp -1
555 .IP "  2." 4.2
557 otherwise,
558 \fIrefs/<refname>\fR
559 if it exists;
562 .RS 4
563 .ie n \{\
564 \h'-04' 3.\h'+01'\c
566 .el \{\
567 .sp -1
568 .IP "  3." 4.2
570 otherwise,
571 \fIrefs/tags/<refname>\fR
572 if it exists;
575 .RS 4
576 .ie n \{\
577 \h'-04' 4.\h'+01'\c
579 .el \{\
580 .sp -1
581 .IP "  4." 4.2
583 otherwise,
584 \fIrefs/heads/<refname>\fR
585 if it exists;
588 .RS 4
589 .ie n \{\
590 \h'-04' 5.\h'+01'\c
592 .el \{\
593 .sp -1
594 .IP "  5." 4.2
596 otherwise,
597 \fIrefs/remotes/<refname>\fR
598 if it exists;
601 .RS 4
602 .ie n \{\
603 \h'-04' 6.\h'+01'\c
605 .el \{\
606 .sp -1
607 .IP "  6." 4.2
609 otherwise,
610 \fIrefs/remotes/<refname>/HEAD\fR
611 if it exists\&.
614 \fBHEAD\fR
615 .RS 4
616 names the commit on which you based the changes in the working tree\&.
619 \fBFETCH_HEAD\fR
620 .RS 4
621 records the branch which you fetched from a remote repository with your last
622 \fBgit fetch\fR
623 invocation\&.
626 \fBORIG_HEAD\fR
627 .RS 4
628 is created by commands that move your
629 \fBHEAD\fR
630 in a drastic way (\fBgit am\fR,
631 \fBgit merge\fR,
632 \fBgit rebase\fR,
633 \fBgit reset\fR), to record the position of the
634 \fBHEAD\fR
635 before their operation, so that you can easily change the tip of the branch back to the state before you ran them\&.
638 \fBMERGE_HEAD\fR
639 .RS 4
640 records the commit(s) which you are merging into your branch when you run
641 \fBgit merge\fR\&.
644 \fBREBASE_HEAD\fR
645 .RS 4
646 during a rebase, records the commit at which the operation is currently stopped, either because of conflicts or an
647 \fBedit\fR
648 command in an interactive rebase\&.
651 \fBREVERT_HEAD\fR
652 .RS 4
653 records the commit which you are reverting when you run
654 \fBgit revert\fR\&.
657 \fBCHERRY_PICK_HEAD\fR
658 .RS 4
659 records the commit which you are cherry\-picking when you run
660 \fBgit cherry\-pick\fR\&.
663 \fBBISECT_HEAD\fR
664 .RS 4
665 records the current commit to be tested when you run
666 \fBgit bisect \-\-no\-checkout\fR\&.
669 \fBAUTO_MERGE\fR
670 .RS 4
671 records a tree object corresponding to the state the
672 \fIort\fR
673 merge strategy wrote to the working tree when a merge operation resulted in conflicts\&.
676 Note that any of the
677 \fIrefs/*\fR
678 cases above may come either from the
679 \fB$GIT_DIR/refs\fR
680 directory or from the
681 \fB$GIT_DIR/packed\-refs\fR
682 file\&. While the ref name encoding is unspecified, UTF\-8 is preferred as some output processing may assume ref names in UTF\-8\&.
685 \fI@\fR
686 .RS 4
687 \fI@\fR
688 alone is a shortcut for
689 \fBHEAD\fR\&.
692 \fI[<refname>]@{<date>}\fR, e\&.g\&. \fImaster@{yesterday}\fR, \fIHEAD@{5 minutes ago}\fR
693 .RS 4
694 A ref followed by the suffix
695 \fI@\fR
696 with a date specification enclosed in a brace pair (e\&.g\&.
697 \fI{yesterday}\fR,
698 \fI{1 month 2 weeks 3 days 1 hour 1 second ago}\fR
700 \fI{1979\-02\-26 18:30:00}\fR) specifies 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 (\fI$GIT_DIR/logs/<ref>\fR)\&. Note that this looks up the state of your
701 \fBlocal\fR
702 ref at a given time; e\&.g\&., what was in your local
703 \fImaster\fR
704 branch last week\&. If you want to look at commits made during certain times, see
705 \fB\-\-since\fR
707 \fB\-\-until\fR\&.
710 \fI<refname>@{<n>}\fR, e\&.g\&. \fImaster@{1}\fR
711 .RS 4
712 A ref followed by the suffix
713 \fI@\fR
714 with an ordinal specification enclosed in a brace pair (e\&.g\&.
715 \fI{1}\fR,
716 \fI{15}\fR) specifies the n\-th prior value of that ref\&. For example
717 \fImaster@{1}\fR
718 is the immediate prior value of
719 \fImaster\fR
720 while
721 \fImaster@{5}\fR
722 is the 5th prior value of
723 \fImaster\fR\&. This suffix may only be used immediately following a ref name and the ref must have an existing log (\fI$GIT_DIR/logs/<refname>\fR)\&.
726 \fI@{<n>}\fR, e\&.g\&. \fI@{1}\fR
727 .RS 4
728 You can use the
729 \fI@\fR
730 construct with an empty ref part to get at a reflog entry of the current branch\&. For example, if you are on branch
731 \fIblabla\fR
732 then
733 \fI@{1}\fR
734 means the same as
735 \fIblabla@{1}\fR\&.
738 \fI@{\-<n>}\fR, e\&.g\&. \fI@{\-1}\fR
739 .RS 4
740 The construct
741 \fI@{\-<n>}\fR
742 means the <n>th branch/commit checked out before the current one\&.
745 \fI[<branchname>]@{upstream}\fR, e\&.g\&. \fImaster@{upstream}\fR, \fI@{u}\fR
746 .RS 4
747 A branch B may be set up to build on top of a branch X (configured with
748 \fBbranch\&.<name>\&.merge\fR) at a remote R (configured with the branch X taken from remote R, typically found at
749 \fBrefs/remotes/R/X\fR\&.
752 \fI[<branchname>]@{push}\fR, e\&.g\&. \fImaster@{push}\fR, \fI@{push}\fR
753 .RS 4
754 The suffix
755 \fI@{push}\fR
756 reports the branch "where we would push to" if
757 \fBgit push\fR
758 were run while
759 \fBbranchname\fR
760 was checked out (or the current
761 \fBHEAD\fR
762 if no branchname is specified)\&. Like for
763 \fI@{upstream}\fR, we report the remote\-tracking branch that corresponds to that branch at the remote\&.
765 Here\(cqs an example to make it more clear:
767 .if n \{\
768 .RS 4
771 $ git config push\&.default current
772 $ git config remote\&.pushdefault myfork
773 $ git switch \-c mybranch origin/master
775 $ git rev\-parse \-\-symbolic\-full\-name @{upstream}
776 refs/remotes/origin/master
778 $ git rev\-parse \-\-symbolic\-full\-name @{push}
779 refs/remotes/myfork/mybranch
781 .if n \{\
785 Note in the example that we set up a triangular workflow, where we pull from one location and push to another\&. In a non\-triangular workflow,
786 \fI@{push}\fR
787 is the same as
788 \fI@{upstream}\fR, and there is no need for it\&.
790 This suffix is also accepted when spelled in uppercase, and means the same thing no matter the case\&.
793 \fI<rev>^[<n>]\fR, e\&.g\&. \fIHEAD^, v1\&.5\&.1^0\fR
794 .RS 4
795 A suffix
796 \fI^\fR
797 to a revision parameter means the first parent of that commit object\&.
798 \fI^<n>\fR
799 means the <n>th parent (i\&.e\&.
800 \fI<rev>^\fR
801 is equivalent to
802 \fI<rev>^1\fR)\&. As a special rule,
803 \fI<rev>^0\fR
804 means the commit itself and is used when
805 \fI<rev>\fR
806 is the object name of a tag object that refers to a commit object\&.
809 \fI<rev>~[<n>]\fR, e\&.g\&. \fIHEAD~, master~3\fR
810 .RS 4
811 A suffix
812 \fI~\fR
813 to a revision parameter means the first parent of that commit object\&. A suffix
814 \fI~<n>\fR
815 to a revision parameter means the commit object that is the <n>th generation ancestor of the named commit object, following only the first parents\&. I\&.e\&.
816 \fI<rev>~3\fR
817 is equivalent to
818 \fI<rev>^^^\fR
819 which is equivalent to
820 \fI<rev>^1^1^1\fR\&. See below for an illustration of the usage of this form\&.
823 \fI<rev>^{<type>}\fR, e\&.g\&. \fIv0\&.99\&.8^{commit}\fR
824 .RS 4
825 A suffix
826 \fI^\fR
827 followed by an object type name enclosed in brace pair means dereference the object at
828 \fI<rev>\fR
829 recursively until an object of type
830 \fI<type>\fR
831 is found or the object cannot be dereferenced anymore (in which case, barf)\&. For example, if
832 \fI<rev>\fR
833 is a commit\-ish,
834 \fI<rev>^{commit}\fR
835 describes the corresponding commit object\&. Similarly, if
836 \fI<rev>\fR
837 is a tree\-ish,
838 \fI<rev>^{tree}\fR
839 describes the corresponding tree object\&.
840 \fI<rev>^0\fR
841 is a short\-hand for
842 \fI<rev>^{commit}\fR\&.
844 \fI<rev>^{object}\fR
845 can be used to make sure
846 \fI<rev>\fR
847 names an object that exists, without requiring
848 \fI<rev>\fR
849 to be a tag, and without dereferencing
850 \fI<rev>\fR; because a tag is already an object, it does not have to be dereferenced even once to get to an object\&.
852 \fI<rev>^{tag}\fR
853 can be used to ensure that
854 \fI<rev>\fR
855 identifies an existing tag object\&.
858 \fI<rev>^{}\fR, e\&.g\&. \fIv0\&.99\&.8^{}\fR
859 .RS 4
860 A suffix
861 \fI^\fR
862 followed by an empty brace pair means the object could be a tag, and dereference the tag recursively until a non\-tag object is found\&.
865 \fI<rev>^{/<text>}\fR, e\&.g\&. \fIHEAD^{/fix nasty bug}\fR
866 .RS 4
867 A suffix
868 \fI^\fR
869 to a revision parameter, followed by a brace pair that contains a text led by a slash, is the same as the
870 \fI:/fix nasty bug\fR
871 syntax below except that it returns the youngest matching commit which is reachable from the
872 \fI<rev>\fR
873 before
874 \fI^\fR\&.
877 \fI:/<text>\fR, e\&.g\&. \fI:/fix nasty bug\fR
878 .RS 4
879 A colon, followed by a slash, followed by a text, names a commit whose commit message matches the specified regular expression\&. This name returns the youngest matching commit which is reachable from any ref, including HEAD\&. The regular expression can match any part of the commit message\&. To match messages starting with a string, one can use e\&.g\&.
880 \fI:/^foo\fR\&. The special sequence
881 \fI:/!\fR
882 is reserved for modifiers to what is matched\&.
883 \fI:/!\-foo\fR
884 performs a negative match, while
885 \fI:/!!foo\fR
886 matches a literal
887 \fI!\fR
888 character, followed by
889 \fIfoo\fR\&. Any other sequence beginning with
890 \fI:/!\fR
891 is reserved for now\&. Depending on the given text, the shell\(cqs word splitting rules might require additional quoting\&.
894 \fI<rev>:<path>\fR, e\&.g\&. \fIHEAD:README\fR, \fImaster:\&./README\fR
895 .RS 4
896 A suffix
897 \fI:\fR
898 followed by a path names the blob or tree at the given path in the tree\-ish object named by the part before the colon\&. A path starting with
899 \fI\&./\fR
901 \fI\&.\&./\fR
902 is relative to the current working directory\&. The given path will be converted to be relative to the working tree\(cqs root directory\&. This is most useful to address a blob or tree from a commit or tree that has the same tree structure as the working tree\&.
905 \fI:[<n>:]<path>\fR, e\&.g\&. \fI:0:README\fR, \fI:README\fR
906 .RS 4
907 A colon, optionally followed by a stage number (0 to 3) and a colon, followed by a path, names a blob object in the index at the given path\&. A 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\(cqs version (typically the current branch), and stage 3 is the version from the branch which is being merged\&.
910 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\&.
912 .if n \{\
913 .RS 4
916 G   H   I   J
917  \e /     \e /
918   D   E   F
919    \e  |  / \e
920     \e | /   |
921      \e|/    |
922       B     C
923        \e   /
924         \e /
925          A
927 .if n \{\
931 .if n \{\
932 .RS 4
935 A =      = A^0
936 B = A^   = A^1     = A~1
937 C =      = A^2
938 D = A^^  = A^1^1   = A~2
939 E = B^2  = A^^2
940 F = B^3  = A^^3
941 G = A^^^ = A^1^1^1 = A~3
942 H = D^2  = B^^2    = A^^^2  = A~2^2
943 I = F^   = B^3^    = A^^3^
944 J = F^2  = B^3^2   = A^^3^2
946 .if n \{\
949 .SH "SPECIFYING RANGES"
951 History traversing commands such as \fBgit log\fR operate on a set of commits, not just a single commit\&.
953 For these commands, specifying a single revision, using the notation described in the previous section, means the set of commits \fBreachable\fR from the given commit\&.
955 Specifying several revisions means the set of commits reachable from any of the given commits\&.
957 A commit\(cqs reachable set is the commit itself and the commits in its ancestry chain\&.
959 There are several notations to specify a set of connected commits (called a "revision range"), illustrated below\&.
960 .SS "Commit Exclusions"
962 \fI^<rev>\fR (caret) Notation
963 .RS 4
964 To exclude commits reachable from a commit, a prefix
965 \fI^\fR
966 notation is used\&. E\&.g\&.
967 \fI^r1 r2\fR
968 means commits reachable from
969 \fIr2\fR
970 but exclude the ones reachable from
971 \fIr1\fR
972 (i\&.e\&.
973 \fIr1\fR
974 and its ancestors)\&.
976 .SS "Dotted Range Notations"
978 The \fI\&.\&.\fR (two\-dot) Range Notation
979 .RS 4
981 \fI^r1 r2\fR
982 set operation appears so often that there is a shorthand for it\&. When you have two commits
983 \fIr1\fR
985 \fIr2\fR
986 (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
987 \fI^r1 r2\fR
988 and it can be written as
989 \fIr1\&.\&.r2\fR\&.
992 The \fI\&.\&.\&.\fR (three\-dot) Symmetric Difference Notation
993 .RS 4
994 A similar notation
995 \fIr1\&.\&.\&.r2\fR
996 is called symmetric difference of
997 \fIr1\fR
999 \fIr2\fR
1000 and is defined as
1001 \fIr1 r2 \-\-not $(git merge\-base \-\-all r1 r2)\fR\&. It is the set of commits that are reachable from either one of
1002 \fIr1\fR
1003 (left side) or
1004 \fIr2\fR
1005 (right side) but not from both\&.
1008 In these two shorthand notations, you can omit one end and let it default to HEAD\&. For example, \fIorigin\&.\&.\fR is a shorthand for \fIorigin\&.\&.HEAD\fR and asks "What did I do since I forked from the origin branch?" Similarly, \fI\&.\&.origin\fR is a shorthand for \fIHEAD\&.\&.origin\fR and asks "What did the origin do since I forked from them?" Note that \fI\&.\&.\fR would mean \fIHEAD\&.\&.HEAD\fR which is an empty range that is both reachable and unreachable from HEAD\&.
1010 Commands that are specifically designed to take two distinct ranges (e\&.g\&. "git range\-diff R1 R2" to compare two ranges) do exist, but they are exceptions\&. Unless otherwise noted, all "git" commands that operate on a set of commits work on a single revision range\&. In other words, writing two "two\-dot range notation" next to each other, e\&.g\&.
1012 .if n \{\
1013 .RS 4
1016 $ git log A\&.\&.B C\&.\&.D
1018 .if n \{\
1022 does \fBnot\fR specify two revision ranges for most commands\&. Instead it will name a single connected set of commits, i\&.e\&. those that are reachable from either B or D but are reachable from neither A or C\&. In a linear history like this:
1024 .if n \{\
1025 .RS 4
1028 \-\-\-A\-\-\-B\-\-\-o\-\-\-o\-\-\-C\-\-\-D
1030 .if n \{\
1034 because A and B are reachable from C, the revision range specified by these two dotted ranges is a single commit D\&.
1035 .SS "Other <rev>^ Parent Shorthand Notations"
1037 Three other shorthands exist, particularly useful for merge commits, for naming a set that is formed by a commit and its parent commits\&.
1039 The \fIr1^@\fR notation means all parents of \fIr1\fR\&.
1041 The \fIr1^!\fR notation includes commit \fIr1\fR but excludes all of its parents\&. By itself, this notation denotes the single commit \fIr1\fR\&.
1043 The \fI<rev>^\-[<n>]\fR notation includes \fI<rev>\fR but excludes the <n>th parent (i\&.e\&. a shorthand for \fI<rev>^<n>\&.\&.<rev>\fR), with \fI<n>\fR = 1 if not given\&. This is typically useful for merge commits where you can just pass \fI<commit>^\-\fR to get all the commits in the branch that was merged in merge commit \fI<commit>\fR (including \fI<commit>\fR itself)\&.
1045 While \fI<rev>^<n>\fR was about specifying a single commit parent, these three notations also consider its parents\&. For example you can say \fIHEAD^2^@\fR, however you cannot say \fIHEAD^@^2\fR\&.
1046 .SH "REVISION RANGE SUMMARY"
1048 \fI<rev>\fR
1049 .RS 4
1050 Include commits that are reachable from <rev> (i\&.e\&. <rev> and its ancestors)\&.
1053 \fI^<rev>\fR
1054 .RS 4
1055 Exclude commits that are reachable from <rev> (i\&.e\&. <rev> and its ancestors)\&.
1058 \fI<rev1>\&.\&.<rev2>\fR
1059 .RS 4
1060 Include commits that are reachable from <rev2> but exclude those that are reachable from <rev1>\&. When either <rev1> or <rev2> is omitted, it defaults to
1061 \fBHEAD\fR\&.
1064 \fI<rev1>\&.\&.\&.<rev2>\fR
1065 .RS 4
1066 Include commits that are reachable from either <rev1> or <rev2> but exclude those that are reachable from both\&. When either <rev1> or <rev2> is omitted, it defaults to
1067 \fBHEAD\fR\&.
1070 \fI<rev>^@\fR, e\&.g\&. \fIHEAD^@\fR
1071 .RS 4
1072 A suffix
1073 \fI^\fR
1074 followed by an at sign is the same as listing all parents of
1075 \fI<rev>\fR
1076 (meaning, include anything reachable from its parents, but not the commit itself)\&.
1079 \fI<rev>^!\fR, e\&.g\&. \fIHEAD^!\fR
1080 .RS 4
1081 A suffix
1082 \fI^\fR
1083 followed by an exclamation mark is the same as giving commit
1084 \fI<rev>\fR
1085 and all its parents prefixed with
1086 \fI^\fR
1087 to exclude them (and their ancestors)\&.
1090 \fI<rev>^\-<n>\fR, e\&.g\&. \fIHEAD^\-, HEAD^\-2\fR
1091 .RS 4
1092 Equivalent to
1093 \fI<rev>^<n>\&.\&.<rev>\fR, with
1094 \fI<n>\fR
1095 = 1 if not given\&.
1098 Here are a handful of examples using the Loeliger illustration above, with each step in the notation\(cqs expansion and selection carefully spelt out:
1100 .if n \{\
1101 .RS 4
1104    Args   Expanded arguments    Selected commits
1105    D                            G H D
1106    D F                          G H I J D F
1107    ^G D                         H D
1108    ^D B                         E I J F B
1109    ^D B C                       E I J F B C
1110    C                            I J F C
1111    B\&.\&.C   = ^B C                C
1112    B\&.\&.\&.C  = B ^F C              G H D E B C
1113    B^\-    = B^\&.\&.B
1114           = ^B^1 B              E I J F B
1115    C^@    = C^1
1116           = F                   I J F
1117    B^@    = B^1 B^2 B^3
1118           = D E F               D G H E F I J
1119    C^!    = C ^C^@
1120           = C ^C^1
1121           = C ^F                C
1122    B^!    = B ^B^@
1123           = B ^B^1 ^B^2 ^B^3
1124           = B ^D ^E ^F          B
1125    F^! D  = F ^I ^J D           G H D F
1127 .if n \{\
1130 .SH "PARSEOPT"
1132 In \fB\-\-parseopt\fR mode, \fIgit rev\-parse\fR 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 \fBgetopt(1)\fR does\&.
1134 It takes on the standard input the specification of the options to parse and understand, and echoes on the standard output a string suitable for \fBsh(1)\fR \fBeval\fR to replace the arguments with normalized ones\&. In case of error, it outputs usage on the standard error stream, and exits with code 129\&.
1136 Note: Make sure you quote the result when passing it to \fBeval\fR\&. See below for an example\&.
1137 .SS "Input Format"
1139 \fIgit rev\-parse \-\-parseopt\fR input format is fully text based\&. It has two parts, separated by a line that contains only \fB\-\-\fR\&. The lines before the separator (should be one or more) are used for the usage\&. The lines after the separator describe the options\&.
1141 Each line of options has this format:
1143 .if n \{\
1144 .RS 4
1147 <opt\-spec><flags>*<arg\-hint>? SP+ help LF
1149 .if n \{\
1155 \fB<opt\-spec>\fR
1156 .RS 4
1157 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\&. May not contain any of the
1158 \fB<flags>\fR
1159 characters\&.
1160 \fBh,help\fR,
1161 \fBdry\-run\fR
1163 \fBf\fR
1164 are examples of correct
1165 \fB<opt\-spec>\fR\&.
1168 \fB<flags>\fR
1169 .RS 4
1170 \fB<flags>\fR
1171 are of
1172 \fB*\fR,
1173 \fB=\fR,
1174 \fB?\fR
1176 \fB!\fR\&.
1178 .RS 4
1179 .ie n \{\
1180 \h'-04'\(bu\h'+03'\c
1182 .el \{\
1183 .sp -1
1184 .IP \(bu 2.3
1187 \fB=\fR
1188 if the option takes an argument\&.
1191 .RS 4
1192 .ie n \{\
1193 \h'-04'\(bu\h'+03'\c
1195 .el \{\
1196 .sp -1
1197 .IP \(bu 2.3
1200 \fB?\fR
1201 to mean that the option takes an optional argument\&. You probably want to use the
1202 \fB\-\-stuck\-long\fR
1203 mode to be able to unambiguously parse the optional argument\&.
1206 .RS 4
1207 .ie n \{\
1208 \h'-04'\(bu\h'+03'\c
1210 .el \{\
1211 .sp -1
1212 .IP \(bu 2.3
1215 \fB*\fR
1216 to mean that this option should not be listed in the usage generated for the
1217 \fB\-h\fR
1218 argument\&. It\(cqs shown for
1219 \fB\-\-help\-all\fR
1220 as documented in
1221 \fBgitcli\fR(7)\&.
1224 .RS 4
1225 .ie n \{\
1226 \h'-04'\(bu\h'+03'\c
1228 .el \{\
1229 .sp -1
1230 .IP \(bu 2.3
1233 \fB!\fR
1234 to not make the corresponding negated long option available\&.
1238 \fB<arg\-hint>\fR
1239 .RS 4
1240 \fB<arg\-hint>\fR, if specified, is used as a name of the argument in the help output, for options that take arguments\&.
1241 \fB<arg\-hint>\fR
1242 is terminated by the first whitespace\&. It is customary to use a dash to separate words in a multi\-word argument hint\&.
1245 The remainder of the line, after stripping the spaces, is used as the help associated with the option\&.
1247 Blank lines are ignored, and lines that don\(cqt match this specification are used as option group headers (start the line with a space to create such lines on purpose)\&.
1248 .SS "Example"
1250 .if n \{\
1251 .RS 4
1254 OPTS_SPEC="\e
1255 some\-command [<options>] <args>\&.\&.\&.
1257 some\-command does foo and bar!
1258 \-\-
1259 h,help!   show the help
1261 foo       some nifty option \-\-foo
1262 bar=      some cool option \-\-bar with an argument
1263 baz=arg   another cool option \-\-baz with a named argument
1264 qux?path  qux may take a path argument but has meaning by itself
1266   An option group Header
1267 C?        option C with an optional argument"
1269 eval "$(echo "$OPTS_SPEC" | git rev\-parse \-\-parseopt \-\- "$@" || echo exit $?)"
1271 .if n \{\
1275 .SS "Usage text"
1277 When \fB"$@"\fR is \fB\-h\fR or \fB\-\-help\fR in the above example, the following usage text would be shown:
1279 .if n \{\
1280 .RS 4
1283 usage: some\-command [<options>] <args>\&.\&.\&.
1285     some\-command does foo and bar!
1287     \-h, \-\-help            show the help
1288     \-\-[no\-]foo            some nifty option \-\-foo
1289     \-\-[no\-]bar \&.\&.\&.        some cool option \-\-bar with an argument
1290     \-\-[no\-]baz <arg>      another cool option \-\-baz with a named argument
1291     \-\-[no\-]qux[=<path>]   qux may take a path argument but has meaning by itself
1293 An option group Header
1294     \-C[\&.\&.\&.]               option C with an optional argument
1296 .if n \{\
1300 .SH "SQ\-QUOTE"
1302 In \fB\-\-sq\-quote\fR mode, \fIgit rev\-parse\fR echoes on the standard output a single line suitable for \fBsh(1)\fR \fBeval\fR\&. This line is made by normalizing the arguments following \fB\-\-sq\-quote\fR\&. Nothing other than quoting the arguments is done\&.
1304 If you want command input to still be interpreted as usual by \fIgit rev\-parse\fR before the output is shell quoted, see the \fB\-\-sq\fR option\&.
1305 .SS "Example"
1307 .if n \{\
1308 .RS 4
1311 $ cat >your\-git\-script\&.sh <<\eEOF
1312 #!/bin/sh
1313 args=$(git rev\-parse \-\-sq\-quote "$@")   # quote user\-supplied arguments
1314 command="git frotz \-n24 $args"          # and use it inside a handcrafted
1315                                         # command line
1316 eval "$command"
1319 $ sh your\-git\-script\&.sh "a b\*(Aqc"
1321 .if n \{\
1325 .SH "EXAMPLES"
1327 .RS 4
1328 .ie n \{\
1329 \h'-04'\(bu\h'+03'\c
1331 .el \{\
1332 .sp -1
1333 .IP \(bu 2.3
1335 Print the object name of the current commit:
1337 .if n \{\
1338 .RS 4
1341 $ git rev\-parse \-\-verify HEAD
1343 .if n \{\
1349 .RS 4
1350 .ie n \{\
1351 \h'-04'\(bu\h'+03'\c
1353 .el \{\
1354 .sp -1
1355 .IP \(bu 2.3
1357 Print the commit object name from the revision in the $REV shell variable:
1359 .if n \{\
1360 .RS 4
1363 $ git rev\-parse \-\-verify \-\-end\-of\-options $REV^{commit}
1365 .if n \{\
1369 This will error out if $REV is empty or not a valid revision\&.
1372 .RS 4
1373 .ie n \{\
1374 \h'-04'\(bu\h'+03'\c
1376 .el \{\
1377 .sp -1
1378 .IP \(bu 2.3
1380 Similar to above:
1382 .if n \{\
1383 .RS 4
1386 $ git rev\-parse \-\-default master \-\-verify \-\-end\-of\-options $REV
1388 .if n \{\
1392 but if $REV is empty, the commit object name from master will be printed\&.
1394 .SH "GIT"
1396 Part of the \fBgit\fR(1) suite