updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-rev-parse.xml
blob7cdd21b8dc2895b89be1972f41f14be0246b182e
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-rev-parse(1)">\r
5 <articleinfo>\r
6     <title>git-rev-parse(1)</title>\r
7 <indexterm>\r
8 <primary>git-rev-parse(1)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-rev-parse - Pick out and massage parameters</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git rev-parse</emphasis> [ --option ] &lt;args&gt;&#8230;</literallayout>\r
19 </blockquote>\r
20 </simplesect>\r
21 <simplesect id="_description">\r
22 <title>DESCRIPTION</title>\r
23 <simpara>Many git porcelainish commands take mixture of flags\r
24 (i.e. parameters that begin with a dash <emphasis>-</emphasis>) and parameters\r
25 meant for the underlying <emphasis>git rev-list</emphasis> command they use internally\r
26 and flags and parameters for the other commands they use\r
27 downstream of <emphasis>git rev-list</emphasis>.  This command is used to\r
28 distinguish between them.</simpara>\r
29 </simplesect>\r
30 <simplesect id="_options">\r
31 <title>OPTIONS</title>\r
32 <variablelist>\r
33 <varlistentry>\r
34 <term>\r
35 --parseopt\r
36 </term>\r
37 <listitem>\r
38 <simpara>\r
39         Use <emphasis>git rev-parse</emphasis> in option parsing mode (see PARSEOPT section below).\r
40 </simpara>\r
41 </listitem>\r
42 </varlistentry>\r
43 <varlistentry>\r
44 <term>\r
45 --keep-dashdash\r
46 </term>\r
47 <listitem>\r
48 <simpara>\r
49         Only meaningful in <emphasis>--parseopt</emphasis> mode. Tells the option parser to echo\r
50         out the first <emphasis>--</emphasis> met instead of skipping it.\r
51 </simpara>\r
52 </listitem>\r
53 </varlistentry>\r
54 <varlistentry>\r
55 <term>\r
56 --stop-at-non-option\r
57 </term>\r
58 <listitem>\r
59 <simpara>\r
60         Only meaningful in <emphasis>--parseopt</emphasis> mode.  Lets the option parser stop at\r
61         the first non-option argument.  This can be used to parse sub-commands\r
62         that take options themselves.\r
63 </simpara>\r
64 </listitem>\r
65 </varlistentry>\r
66 <varlistentry>\r
67 <term>\r
68 --sq-quote\r
69 </term>\r
70 <listitem>\r
71 <simpara>\r
72         Use <emphasis>git rev-parse</emphasis> in shell quoting mode (see SQ-QUOTE\r
73         section below). In contrast to the <emphasis>--sq</emphasis> option below, this\r
74         mode does only quoting. Nothing else is done to command input.\r
75 </simpara>\r
76 </listitem>\r
77 </varlistentry>\r
78 <varlistentry>\r
79 <term>\r
80 --revs-only\r
81 </term>\r
82 <listitem>\r
83 <simpara>\r
84         Do not output flags and parameters not meant for\r
85         <emphasis>git rev-list</emphasis> command.\r
86 </simpara>\r
87 </listitem>\r
88 </varlistentry>\r
89 <varlistentry>\r
90 <term>\r
91 --no-revs\r
92 </term>\r
93 <listitem>\r
94 <simpara>\r
95         Do not output flags and parameters meant for\r
96         <emphasis>git rev-list</emphasis> command.\r
97 </simpara>\r
98 </listitem>\r
99 </varlistentry>\r
100 <varlistentry>\r
101 <term>\r
102 --flags\r
103 </term>\r
104 <listitem>\r
105 <simpara>\r
106         Do not output non-flag parameters.\r
107 </simpara>\r
108 </listitem>\r
109 </varlistentry>\r
110 <varlistentry>\r
111 <term>\r
112 --no-flags\r
113 </term>\r
114 <listitem>\r
115 <simpara>\r
116         Do not output flag parameters.\r
117 </simpara>\r
118 </listitem>\r
119 </varlistentry>\r
120 <varlistentry>\r
121 <term>\r
122 --default &lt;arg&gt;\r
123 </term>\r
124 <listitem>\r
125 <simpara>\r
126         If there is no parameter given by the user, use <emphasis>&lt;arg&gt;</emphasis>\r
127         instead.\r
128 </simpara>\r
129 </listitem>\r
130 </varlistentry>\r
131 <varlistentry>\r
132 <term>\r
133 --verify\r
134 </term>\r
135 <listitem>\r
136 <simpara>\r
137         The parameter given must be usable as a single, valid\r
138         object name.  Otherwise barf and abort.\r
139 </simpara>\r
140 </listitem>\r
141 </varlistentry>\r
142 <varlistentry>\r
143 <term>\r
144 -q\r
145 </term>\r
146 <term>\r
147 --quiet\r
148 </term>\r
149 <listitem>\r
150 <simpara>\r
151         Only meaningful in <emphasis>--verify</emphasis> mode. Do not output an error\r
152         message if the first argument is not a valid object name;\r
153         instead exit with non-zero status silently.\r
154 </simpara>\r
155 </listitem>\r
156 </varlistentry>\r
157 <varlistentry>\r
158 <term>\r
159 --sq\r
160 </term>\r
161 <listitem>\r
162 <simpara>\r
163         Usually the output is made one line per flag and\r
164         parameter.  This option makes output a single line,\r
165         properly quoted for consumption by shell.  Useful when\r
166         you expect your parameter to contain whitespaces and\r
167         newlines (e.g. when using pickaxe <emphasis>-S</emphasis> with\r
168         <emphasis>git diff-&#42;</emphasis>). In contrast to the <emphasis>--sq-quote</emphasis> option,\r
169         the command input is still interpreted as usual.\r
170 </simpara>\r
171 </listitem>\r
172 </varlistentry>\r
173 <varlistentry>\r
174 <term>\r
175 --not\r
176 </term>\r
177 <listitem>\r
178 <simpara>\r
179         When showing object names, prefix them with <emphasis>&#94;</emphasis> and\r
180         strip <emphasis>&#94;</emphasis> prefix from the object names that already have\r
181         one.\r
182 </simpara>\r
183 </listitem>\r
184 </varlistentry>\r
185 <varlistentry>\r
186 <term>\r
187 --symbolic\r
188 </term>\r
189 <listitem>\r
190 <simpara>\r
191         Usually the object names are output in SHA1 form (with\r
192         possible <emphasis>&#94;</emphasis> prefix); this option makes them output in a\r
193         form as close to the original input as possible.\r
194 </simpara>\r
195 </listitem>\r
196 </varlistentry>\r
197 <varlistentry>\r
198 <term>\r
199 --symbolic-full-name\r
200 </term>\r
201 <listitem>\r
202 <simpara>\r
203         This is similar to --symbolic, but it omits input that\r
204         are not refs (i.e. branch or tag names; or more\r
205         explicitly disambiguating "heads/master" form, when you\r
206         want to name the "master" branch when there is an\r
207         unfortunately named tag "master"), and show them as full\r
208         refnames (e.g. "refs/heads/master").\r
209 </simpara>\r
210 </listitem>\r
211 </varlistentry>\r
212 <varlistentry>\r
213 <term>\r
214 --abbrev-ref[=(strict|loose)]\r
215 </term>\r
216 <listitem>\r
217 <simpara>\r
218         A non-ambiguous short name of the objects name.\r
219         The option core.warnAmbiguousRefs is used to select the strict\r
220         abbreviation mode.\r
221 </simpara>\r
222 </listitem>\r
223 </varlistentry>\r
224 <varlistentry>\r
225 <term>\r
226 --all\r
227 </term>\r
228 <listitem>\r
229 <simpara>\r
230         Show all refs found in <emphasis>refs/</emphasis>.\r
231 </simpara>\r
232 </listitem>\r
233 </varlistentry>\r
234 <varlistentry>\r
235 <term>\r
236 --branches[=pattern]\r
237 </term>\r
238 <term>\r
239 --tags[=pattern]\r
240 </term>\r
241 <term>\r
242 --remotes[=pattern]\r
243 </term>\r
244 <listitem>\r
245 <simpara>\r
246         Show all branches, tags, or remote-tracking branches,\r
247         respectively (i.e., refs found in <emphasis>refs/heads</emphasis>,\r
248         <emphasis>refs/tags</emphasis>, or <emphasis>refs/remotes</emphasis>, respectively).\r
249 </simpara>\r
250 <simpara>If a <emphasis>pattern</emphasis> is given, only refs matching the given shell glob are\r
251 shown.  If the pattern does not contain a globbing character (<emphasis>?</emphasis>,\r
252 <emphasis>*</emphasis>, or <emphasis>[</emphasis>), it is turned into a prefix match by appending <emphasis>/*</emphasis>.</simpara>\r
253 </listitem>\r
254 </varlistentry>\r
255 <varlistentry>\r
256 <term>\r
257 --glob=pattern\r
258 </term>\r
259 <listitem>\r
260 <simpara>\r
261         Show all refs matching the shell glob pattern <emphasis>pattern</emphasis>. If\r
262         the pattern does not start with <emphasis>refs/</emphasis>, this is automatically\r
263         prepended.  If the pattern does not contain a globbing\r
264         character (<emphasis>?</emphasis>, <emphasis>*</emphasis>, or <emphasis>[</emphasis>), it is turned into a prefix\r
265         match by appending <emphasis>/*</emphasis>.\r
266 </simpara>\r
267 </listitem>\r
268 </varlistentry>\r
269 <varlistentry>\r
270 <term>\r
271 --show-toplevel\r
272 </term>\r
273 <listitem>\r
274 <simpara>\r
275         Show the absolute path of the top-level directory.\r
276 </simpara>\r
277 </listitem>\r
278 </varlistentry>\r
279 <varlistentry>\r
280 <term>\r
281 --show-prefix\r
282 </term>\r
283 <listitem>\r
284 <simpara>\r
285         When the command is invoked from a subdirectory, show the\r
286         path of the current directory relative to the top-level\r
287         directory.\r
288 </simpara>\r
289 </listitem>\r
290 </varlistentry>\r
291 <varlistentry>\r
292 <term>\r
293 --show-cdup\r
294 </term>\r
295 <listitem>\r
296 <simpara>\r
297         When the command is invoked from a subdirectory, show the\r
298         path of the top-level directory relative to the current\r
299         directory (typically a sequence of "../", or an empty string).\r
300 </simpara>\r
301 </listitem>\r
302 </varlistentry>\r
303 <varlistentry>\r
304 <term>\r
305 --git-dir\r
306 </term>\r
307 <listitem>\r
308 <simpara>\r
309         Show <emphasis>$GIT_DIR</emphasis> if defined. Otherwise show the path to\r
310         the .git directory, relative to the current directory.\r
311 </simpara>\r
312 <simpara>If <emphasis>$GIT_DIR</emphasis> is not defined and the current directory\r
313 is not detected to lie in a git repository or work tree\r
314 print a message to stderr and exit with nonzero status.</simpara>\r
315 </listitem>\r
316 </varlistentry>\r
317 <varlistentry>\r
318 <term>\r
319 --is-inside-git-dir\r
320 </term>\r
321 <listitem>\r
322 <simpara>\r
323         When the current working directory is below the repository\r
324         directory print "true", otherwise "false".\r
325 </simpara>\r
326 </listitem>\r
327 </varlistentry>\r
328 <varlistentry>\r
329 <term>\r
330 --is-inside-work-tree\r
331 </term>\r
332 <listitem>\r
333 <simpara>\r
334         When the current working directory is inside the work tree of the\r
335         repository print "true", otherwise "false".\r
336 </simpara>\r
337 </listitem>\r
338 </varlistentry>\r
339 <varlistentry>\r
340 <term>\r
341 --is-bare-repository\r
342 </term>\r
343 <listitem>\r
344 <simpara>\r
345         When the repository is bare print "true", otherwise "false".\r
346 </simpara>\r
347 </listitem>\r
348 </varlistentry>\r
349 <varlistentry>\r
350 <term>\r
351 --local-env-vars\r
352 </term>\r
353 <listitem>\r
354 <simpara>\r
355         List the GIT_* environment variables that are local to the\r
356         repository (e.g. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR).\r
357         Only the names of the variables are listed, not their value,\r
358         even if they are set.\r
359 </simpara>\r
360 </listitem>\r
361 </varlistentry>\r
362 <varlistentry>\r
363 <term>\r
364 --short\r
365 </term>\r
366 <term>\r
367 --short=number\r
368 </term>\r
369 <listitem>\r
370 <simpara>\r
371         Instead of outputting the full SHA1 values of object names try to\r
372         abbreviate them to a shorter unique name. When no length is specified\r
373         7 is used. The minimum length is 4.\r
374 </simpara>\r
375 </listitem>\r
376 </varlistentry>\r
377 <varlistentry>\r
378 <term>\r
379 --since=datestring\r
380 </term>\r
381 <term>\r
382 --after=datestring\r
383 </term>\r
384 <listitem>\r
385 <simpara>\r
386         Parse the date string, and output the corresponding\r
387         --max-age= parameter for <emphasis>git rev-list</emphasis>.\r
388 </simpara>\r
389 </listitem>\r
390 </varlistentry>\r
391 <varlistentry>\r
392 <term>\r
393 --until=datestring\r
394 </term>\r
395 <term>\r
396 --before=datestring\r
397 </term>\r
398 <listitem>\r
399 <simpara>\r
400         Parse the date string, and output the corresponding\r
401         --min-age= parameter for <emphasis>git rev-list</emphasis>.\r
402 </simpara>\r
403 </listitem>\r
404 </varlistentry>\r
405 <varlistentry>\r
406 <term>\r
407 &lt;args&gt;&#8230;\r
408 </term>\r
409 <listitem>\r
410 <simpara>\r
411         Flags and parameters to be parsed.\r
412 </simpara>\r
413 </listitem>\r
414 </varlistentry>\r
415 <varlistentry>\r
416 <term>\r
417 --resolve-git-dir &lt;path&gt;\r
418 </term>\r
419 <listitem>\r
420 <simpara>\r
421         Check if &lt;path&gt; is a valid git-dir or a git-file pointing to a valid\r
422         git-dir. If &lt;path&gt; is a valid git-dir the resolved path to git-dir will\r
423         be printed.\r
424 </simpara>\r
425 </listitem>\r
426 </varlistentry>\r
427 </variablelist>\r
428 </simplesect>\r
429 <simplesect id="_specifying_revisions">\r
430 <title>SPECIFYING REVISIONS</title>\r
431 <simpara>A revision parameter <emphasis>&lt;rev&gt;</emphasis> typically, but not necessarily, names a\r
432 commit object.  It uses what is called an <emphasis>extended SHA1</emphasis>\r
433 syntax.  Here are various ways to spell object names.  The\r
434 ones listed near the end of this list name trees and\r
435 blobs contained in a commit.</simpara>\r
436 <variablelist>\r
437 <varlistentry>\r
438 <term>\r
439 <emphasis>&lt;sha1&gt;</emphasis>, e.g. <emphasis>dae86e1950b1277e545cee180551750029cfe735</emphasis>, <emphasis>dae86e</emphasis>\r
440 </term>\r
441 <listitem>\r
442 <simpara>\r
443   The full SHA1 object name (40-byte hexadecimal string), or\r
444   a leading substring that is unique within the repository.\r
445   E.g. dae86e1950b1277e545cee180551750029cfe735 and dae86e both\r
446   name the same commit object if there is no other object in\r
447   your repository whose object name starts with dae86e.\r
448 </simpara>\r
449 </listitem>\r
450 </varlistentry>\r
451 <varlistentry>\r
452 <term>\r
453 <emphasis>&lt;describeOutput&gt;</emphasis>, e.g. <emphasis>v1.7.4.2-679-g3bee7fb</emphasis>\r
454 </term>\r
455 <listitem>\r
456 <simpara>\r
457   Output from <emphasis>git describe</emphasis>; i.e. a closest tag, optionally\r
458   followed by a dash and a number of commits, followed by a dash, a\r
459   <emphasis>g</emphasis>, and an abbreviated object name.\r
460 </simpara>\r
461 </listitem>\r
462 </varlistentry>\r
463 <varlistentry>\r
464 <term>\r
465 <emphasis>&lt;refname&gt;</emphasis>, e.g. <emphasis>master</emphasis>, <emphasis>heads/master</emphasis>, <emphasis>refs/heads/master</emphasis>\r
466 </term>\r
467 <listitem>\r
468 <simpara>\r
469   A symbolic ref name.  E.g. <emphasis>master</emphasis> typically means the commit\r
470   object referenced by <emphasis>refs/heads/master</emphasis>.  If you\r
471   happen to have both <emphasis>heads/master</emphasis> and <emphasis>tags/master</emphasis>, you can\r
472   explicitly say <emphasis>heads/master</emphasis> to tell git which one you mean.\r
473   When ambiguous, a <emphasis>&lt;name&gt;</emphasis> is disambiguated by taking the\r
474   first match in the following rules:\r
475 </simpara>\r
476 <orderedlist numeration="arabic">\r
477 <listitem>\r
478 <simpara>\r
479 If <emphasis>$GIT_DIR/&lt;name&gt;</emphasis> exists, that is what you mean (this is usually\r
480     useful only for <emphasis>HEAD</emphasis>, <emphasis>FETCH_HEAD</emphasis>, <emphasis>ORIG_HEAD</emphasis>, <emphasis>MERGE_HEAD</emphasis>\r
481     and <emphasis>CHERRY_PICK_HEAD</emphasis>);\r
482 </simpara>\r
483 </listitem>\r
484 <listitem>\r
485 <simpara>\r
486 otherwise, <emphasis>refs/&lt;name&gt;</emphasis> if it exists;\r
487 </simpara>\r
488 </listitem>\r
489 <listitem>\r
490 <simpara>\r
491 otherwise, <emphasis>refs/tags/&lt;refname&gt;</emphasis> if it exists;\r
492 </simpara>\r
493 </listitem>\r
494 <listitem>\r
495 <simpara>\r
496 otherwise, <emphasis>refs/heads/&lt;name&gt;</emphasis> if it exists;\r
497 </simpara>\r
498 </listitem>\r
499 <listitem>\r
500 <simpara>\r
501 otherwise, <emphasis>refs/remotes/&lt;name&gt;</emphasis> if it exists;\r
502 </simpara>\r
503 </listitem>\r
504 <listitem>\r
505 <simpara>\r
506 otherwise, <emphasis>refs/remotes/&lt;name&gt;/HEAD</emphasis> if it exists.\r
507 </simpara>\r
508 <simpara><emphasis>HEAD</emphasis> names the commit on which you based the changes in the working tree.\r
509 <emphasis>FETCH_HEAD</emphasis> records the branch which you fetched from a remote repository\r
510 with your last <emphasis>git fetch</emphasis> invocation.\r
511 <emphasis>ORIG_HEAD</emphasis> is created by commands that move your <emphasis>HEAD</emphasis> in a drastic\r
512 way, to record the position of the <emphasis>HEAD</emphasis> before their operation, so that\r
513 you can easily change the tip of the branch back to the state before you ran\r
514 them.\r
515 <emphasis>MERGE_HEAD</emphasis> records the commit(s) which you are merging into your branch\r
516 when you run <emphasis>git merge</emphasis>.\r
517 <emphasis>CHERRY_PICK_HEAD</emphasis> records the commit which you are cherry-picking\r
518 when you run <emphasis>git cherry-pick</emphasis>.</simpara>\r
519 <simpara>Note that any of the <emphasis>refs/*</emphasis> cases above may come either from\r
520 the <emphasis>$GIT_DIR/refs</emphasis> directory or from the <emphasis>$GIT_DIR/packed-refs</emphasis> file.</simpara>\r
521 </listitem>\r
522 </orderedlist>\r
523 </listitem>\r
524 </varlistentry>\r
525 <varlistentry>\r
526 <term>\r
527 <emphasis>&lt;refname&gt;@{&lt;date&gt;}</emphasis>, e.g. <emphasis>master@{yesterday}</emphasis>, <emphasis>HEAD@{5 minutes ago}</emphasis>\r
528 </term>\r
529 <listitem>\r
530 <simpara>\r
531   A ref followed by the suffix <emphasis>@</emphasis> with a date specification\r
532   enclosed in a brace\r
533   pair (e.g. <emphasis>{yesterday}</emphasis>, <emphasis>{1 month 2 weeks 3 days 1 hour 1\r
534   second ago}</emphasis> or <emphasis>{1979-02-26 18:30:00}</emphasis>) specifies the value\r
535   of the ref at a prior point in time.  This suffix may only be\r
536   used immediately following a ref name and the ref must have an\r
537   existing log (<emphasis>$GIT_DIR/logs/&lt;ref&gt;</emphasis>). Note that this looks up the state\r
538   of your <emphasis role="strong">local</emphasis> ref at a given time; e.g., what was in your local\r
539   <emphasis>master</emphasis> branch last week. If you want to look at commits made during\r
540   certain times, see <emphasis>--since</emphasis> and <emphasis>--until</emphasis>.\r
541 </simpara>\r
542 </listitem>\r
543 </varlistentry>\r
544 <varlistentry>\r
545 <term>\r
546 <emphasis>&lt;refname&gt;@{&lt;n&gt;}</emphasis>, e.g. <emphasis>master@{1}</emphasis>\r
547 </term>\r
548 <listitem>\r
549 <simpara>\r
550   A ref followed by the suffix <emphasis>@</emphasis> with an ordinal specification\r
551   enclosed in a brace pair (e.g. <emphasis>{1}</emphasis>, <emphasis>{15}</emphasis>) specifies\r
552   the n-th prior value of that ref.  For example <emphasis>master@{1}</emphasis>\r
553   is the immediate prior value of <emphasis>master</emphasis> while <emphasis>master@{5}</emphasis>\r
554   is the 5th prior value of <emphasis>master</emphasis>. This suffix may only be used\r
555   immediately following a ref name and the ref must have an existing\r
556   log (<emphasis>$GIT_DIR/logs/&lt;refname&gt;</emphasis>).\r
557 </simpara>\r
558 </listitem>\r
559 </varlistentry>\r
560 <varlistentry>\r
561 <term>\r
562 <emphasis>@{&lt;n&gt;}</emphasis>, e.g. <emphasis>@{1}</emphasis>\r
563 </term>\r
564 <listitem>\r
565 <simpara>\r
566   You can use the <emphasis>@</emphasis> construct with an empty ref part to get at a\r
567   reflog entry of the current branch. For example, if you are on\r
568   branch <emphasis>blabla</emphasis> then <emphasis>@{1}</emphasis> means the same as <emphasis>blabla@{1}</emphasis>.\r
569 </simpara>\r
570 </listitem>\r
571 </varlistentry>\r
572 <varlistentry>\r
573 <term>\r
574 <emphasis>@{-&lt;n&gt;}</emphasis>, e.g. <emphasis>@{-1}</emphasis>\r
575 </term>\r
576 <listitem>\r
577 <simpara>\r
578   The construct <emphasis>@{-&lt;n&gt;}</emphasis> means the &lt;n&gt;th branch checked out\r
579   before the current one.\r
580 </simpara>\r
581 </listitem>\r
582 </varlistentry>\r
583 <varlistentry>\r
584 <term>\r
585 <emphasis>&lt;refname&gt;@{upstream}</emphasis>, e.g. <emphasis>master@{upstream}</emphasis>, <emphasis>@{u}</emphasis>\r
586 </term>\r
587 <listitem>\r
588 <simpara>\r
589   The suffix <emphasis>@{upstream}</emphasis> to a ref (short form <emphasis>&lt;refname&gt;@{u}</emphasis>) refers to\r
590   the branch the ref is set to build on top of.  A missing ref defaults\r
591   to the current branch.\r
592 </simpara>\r
593 </listitem>\r
594 </varlistentry>\r
595 <varlistentry>\r
596 <term>\r
597 <emphasis>&lt;rev&gt;&#94;</emphasis>, e.g. <emphasis>HEAD&#94;, v1.5.1&#94;0</emphasis>\r
598 </term>\r
599 <listitem>\r
600 <simpara>\r
601   A suffix <emphasis>&#94;</emphasis> to a revision parameter means the first parent of\r
602   that commit object.  <emphasis>&#94;&lt;n&gt;</emphasis> means the &lt;n&gt;th parent (i.e.\r
603   <emphasis>&lt;rev&gt;&#94;</emphasis>\r
604   is equivalent to <emphasis>&lt;rev&gt;&#94;1</emphasis>).  As a special rule,\r
605   <emphasis>&lt;rev&gt;&#94;0</emphasis> means the commit itself and is used when <emphasis>&lt;rev&gt;</emphasis> is the\r
606   object name of a tag object that refers to a commit object.\r
607 </simpara>\r
608 </listitem>\r
609 </varlistentry>\r
610 <varlistentry>\r
611 <term>\r
612 <emphasis>&lt;rev&gt;&#126;&lt;n&gt;</emphasis>, e.g. <emphasis>master&#126;3</emphasis>\r
613 </term>\r
614 <listitem>\r
615 <simpara>\r
616   A suffix <emphasis>&#126;&lt;n&gt;</emphasis> to a revision parameter means the commit\r
617   object that is the &lt;n&gt;th generation ancestor of the named\r
618   commit object, following only the first parents.  I.e. <emphasis>&lt;rev&gt;&#126;3</emphasis> is\r
619   equivalent to <emphasis>&lt;rev&gt;&#94;&#94;&#94;</emphasis> which is equivalent to\r
620   <emphasis>&lt;rev&gt;&#94;1&#94;1&#94;1</emphasis>.  See below for an illustration of\r
621   the usage of this form.\r
622 </simpara>\r
623 </listitem>\r
624 </varlistentry>\r
625 <varlistentry>\r
626 <term>\r
627 <emphasis>&lt;rev&gt;&#94;{&lt;type&gt;}</emphasis>, e.g. <emphasis>v0.99.8&#94;{commit}</emphasis>\r
628 </term>\r
629 <listitem>\r
630 <simpara>\r
631   A suffix <emphasis>&#94;</emphasis> followed by an object type name enclosed in\r
632   brace pair means the object\r
633   could be a tag, and dereference the tag recursively until an\r
634   object of that type is found or the object cannot be\r
635   dereferenced anymore (in which case, barf).  <emphasis>&lt;rev&gt;&#94;0</emphasis>\r
636   is a short-hand for <emphasis>&lt;rev&gt;&#94;{commit}</emphasis>.\r
637 </simpara>\r
638 </listitem>\r
639 </varlistentry>\r
640 <varlistentry>\r
641 <term>\r
642 <emphasis>&lt;rev&gt;&#94;{}</emphasis>, e.g. <emphasis>v0.99.8&#94;{}</emphasis>\r
643 </term>\r
644 <listitem>\r
645 <simpara>\r
646   A suffix <emphasis>&#94;</emphasis> followed by an empty brace pair\r
647   means the object could be a tag,\r
648   and dereference the tag recursively until a non-tag object is\r
649   found.\r
650 </simpara>\r
651 </listitem>\r
652 </varlistentry>\r
653 <varlistentry>\r
654 <term>\r
655 <emphasis>&lt;rev&gt;&#94;{/&lt;text&gt;}</emphasis>, e.g. <emphasis>HEAD^{/fix nasty bug}</emphasis>\r
656 </term>\r
657 <listitem>\r
658 <simpara>\r
659   A suffix <emphasis>&#94;</emphasis> to a revision parameter, followed by a brace\r
660   pair that contains a text led by a slash,\r
661   is the same as the <emphasis>:/fix nasty bug</emphasis> syntax below except that\r
662   it returns the youngest matching commit which is reachable from\r
663   the <emphasis>&lt;rev&gt;</emphasis> before <emphasis>&#94;</emphasis>.\r
664 </simpara>\r
665 </listitem>\r
666 </varlistentry>\r
667 <varlistentry>\r
668 <term>\r
669 <emphasis>:/&lt;text&gt;</emphasis>, e.g. <emphasis>:/fix nasty bug</emphasis>\r
670 </term>\r
671 <listitem>\r
672 <simpara>\r
673   A colon, followed by a slash, followed by a text, names\r
674   a commit whose commit message matches the specified regular expression.\r
675   This name returns the youngest matching commit which is\r
676   reachable from any ref.  If the commit message starts with a\r
677   <emphasis>!</emphasis> you have to repeat that;  the special sequence <emphasis>:/!</emphasis>,\r
678   followed by something else than <emphasis>!</emphasis>, is reserved for now.\r
679   The regular expression can match any part of the commit message. To\r
680   match messages starting with a string, one can use e.g. <emphasis>:/^foo</emphasis>.\r
681 </simpara>\r
682 </listitem>\r
683 </varlistentry>\r
684 <varlistentry>\r
685 <term>\r
686 <emphasis>&lt;rev&gt;:&lt;path&gt;</emphasis>, e.g. <emphasis>HEAD:README</emphasis>, <emphasis>:README</emphasis>, <emphasis>master:./README</emphasis>\r
687 </term>\r
688 <listitem>\r
689 <simpara>\r
690   A suffix <emphasis>:</emphasis> followed by a path names the blob or tree\r
691   at the given path in the tree-ish object named by the part\r
692   before the colon.\r
693   <emphasis>:path</emphasis> (with an empty part before the colon)\r
694   is a special case of the syntax described next: content\r
695   recorded in the index at the given path.\r
696   A path starting with <emphasis>./</emphasis> or <emphasis>../</emphasis> is relative to the current working directory.\r
697   The given path will be converted to be relative to the working tree's root directory.\r
698   This is most useful to address a blob or tree from a commit or tree that has\r
699   the same tree structure as the working tree.\r
700 </simpara>\r
701 </listitem>\r
702 </varlistentry>\r
703 <varlistentry>\r
704 <term>\r
705 <emphasis>:&lt;n&gt;:&lt;path&gt;</emphasis>, e.g. <emphasis>:0:README</emphasis>, <emphasis>:README</emphasis>\r
706 </term>\r
707 <listitem>\r
708 <simpara>\r
709   A colon, optionally followed by a stage number (0 to 3) and a\r
710   colon, followed by a path, names a blob object in the\r
711   index at the given path. A missing stage number (and the colon\r
712   that follows it) names a stage 0 entry. During a merge, stage\r
713   1 is the common ancestor, stage 2 is the target branch's version\r
714   (typically the current branch), and stage 3 is the version from\r
715   the branch which is being merged.\r
716 </simpara>\r
717 </listitem>\r
718 </varlistentry>\r
719 </variablelist>\r
720 <simpara>Here is an illustration, by Jon Loeliger.  Both commit nodes B\r
721 and C are parents of commit node A.  Parent commits are ordered\r
722 left-to-right.</simpara>\r
723 <literallayout class="monospaced">G   H   I   J\r
724  \ /     \ /\r
725   D   E   F\r
726    \  |  / \\r
727     \ | /   |\r
728      \|/    |\r
729       B     C\r
730        \   /\r
731         \ /\r
732          A</literallayout>\r
733 <literallayout class="monospaced">A =      = A^0\r
734 B = A^   = A^1     = A~1\r
735 C = A^2  = A^2\r
736 D = A^^  = A^1^1   = A~2\r
737 E = B^2  = A^^2\r
738 F = B^3  = A^^3\r
739 G = A^^^ = A^1^1^1 = A~3\r
740 H = D^2  = B^^2    = A^^^2  = A~2^2\r
741 I = F^   = B^3^    = A^^3^\r
742 J = F^2  = B^3^2   = A^^3^2</literallayout>\r
743 </simplesect>\r
744 <simplesect id="_specifying_ranges">\r
745 <title>SPECIFYING RANGES</title>\r
746 <simpara>History traversing commands such as <emphasis>git log</emphasis> operate on a set\r
747 of commits, not just a single commit.  To these commands,\r
748 specifying a single revision with the notation described in the\r
749 previous section means the set of commits reachable from that\r
750 commit, following the commit ancestry chain.</simpara>\r
751 <simpara>To exclude commits reachable from a commit, a prefix <emphasis>&#94;</emphasis>\r
752 notation is used.  E.g. <emphasis>&#94;r1 r2</emphasis> means commits reachable\r
753 from <emphasis>r2</emphasis> but exclude the ones reachable from <emphasis>r1</emphasis>.</simpara>\r
754 <simpara>This set operation appears so often that there is a shorthand\r
755 for it.  When you have two commits <emphasis>r1</emphasis> and <emphasis>r2</emphasis> (named according\r
756 to the syntax explained in SPECIFYING REVISIONS above), you can ask\r
757 for commits that are reachable from r2 excluding those that are reachable\r
758 from r1 by <emphasis>&#94;r1 r2</emphasis> and it can be written as <emphasis>r1..r2</emphasis>.</simpara>\r
759 <simpara>A similar notation <emphasis>r1...r2</emphasis> is called symmetric difference\r
760 of <emphasis>r1</emphasis> and <emphasis>r2</emphasis> and is defined as\r
761 <emphasis>r1 r2 --not $(git merge-base --all r1 r2)</emphasis>.\r
762 It is the set of commits that are reachable from either one of\r
763 <emphasis>r1</emphasis> or <emphasis>r2</emphasis> but not from both.</simpara>\r
764 <simpara>Two other shorthands for naming a set that is formed by a commit\r
765 and its parent commits exist.  The <emphasis>r1&#94;@</emphasis> notation means all\r
766 parents of <emphasis>r1</emphasis>.  <emphasis>r1&#94;!</emphasis> includes commit <emphasis>r1</emphasis> but excludes\r
767 all of its parents.</simpara>\r
768 <simpara>Here are a handful of examples:</simpara>\r
769 <literallayout class="monospaced">D                G H D\r
770 D F              G H I J D F\r
771 ^G D             H D\r
772 ^D B             E I J F B\r
773 B...C            G H D E B C\r
774 ^D B C           E I J F B C\r
775 C^@              I J F\r
776 F^! D            G H D F</literallayout>\r
777 </simplesect>\r
778 <simplesect id="_parseopt">\r
779 <title>PARSEOPT</title>\r
780 <simpara>In <emphasis>--parseopt</emphasis> mode, <emphasis>git rev-parse</emphasis> helps massaging options to bring to shell\r
781 scripts the same facilities C builtins have. It works as an option normalizer\r
782 (e.g. splits single switches aggregate values), a bit like <emphasis>getopt(1)</emphasis> does.</simpara>\r
783 <simpara>It takes on the standard input the specification of the options to parse and\r
784 understand, and echoes on the standard output a string suitable for <emphasis>sh(1)</emphasis> <emphasis>eval</emphasis>\r
785 to replace the arguments with normalized ones.  In case of error, it outputs\r
786 usage on the standard error stream, and exits with code 129.</simpara>\r
787 <simpara>Note: Make sure you quote the result when passing it to <emphasis>eval</emphasis>.  See\r
788 below for an example.</simpara>\r
789 <section id="_input_format">\r
790 <title>Input Format</title>\r
791 <simpara><emphasis>git rev-parse --parseopt</emphasis> input format is fully text based. It has two parts,\r
792 separated by a line that contains only <emphasis>--</emphasis>. The lines before the separator\r
793 (should be more than one) are used for the usage.\r
794 The lines after the separator describe the options.</simpara>\r
795 <simpara>Each line of options has this format:</simpara>\r
796 <screen>&lt;opt_spec&gt;&lt;flags&gt;* SP+ help LF</screen>\r
797 <variablelist>\r
798 <varlistentry>\r
799 <term>\r
800 <emphasis>&lt;opt_spec&gt;</emphasis>\r
801 </term>\r
802 <listitem>\r
803 <simpara>\r
804         its format is the short option character, then the long option name\r
805         separated by a comma. Both parts are not required, though at least one\r
806         is necessary. <emphasis>h,help</emphasis>, <emphasis>dry-run</emphasis> and <emphasis>f</emphasis> are all three correct\r
807         <emphasis>&lt;opt_spec&gt;</emphasis>.\r
808 </simpara>\r
809 </listitem>\r
810 </varlistentry>\r
811 <varlistentry>\r
812 <term>\r
813 <emphasis>&lt;flags&gt;</emphasis>\r
814 </term>\r
815 <listitem>\r
816 <simpara>\r
817         <emphasis>&lt;flags&gt;</emphasis> are of <emphasis>*</emphasis>, <emphasis>=</emphasis>, <emphasis>?</emphasis> or <emphasis>!</emphasis>.\r
818 </simpara>\r
819 <itemizedlist>\r
820 <listitem>\r
821 <simpara>\r
822 Use <emphasis>=</emphasis> if the option takes an argument.\r
823 </simpara>\r
824 </listitem>\r
825 <listitem>\r
826 <simpara>\r
827 Use <emphasis>?</emphasis> to mean that the option is optional (though its use is discouraged).\r
828 </simpara>\r
829 </listitem>\r
830 <listitem>\r
831 <simpara>\r
832 Use <emphasis>*</emphasis> to mean that this option should not be listed in the usage\r
833           generated for the <emphasis>-h</emphasis> argument. It's shown for <emphasis>--help-all</emphasis> as\r
834           documented in <xref linkend="gitcli(7)" />.\r
835 </simpara>\r
836 </listitem>\r
837 <listitem>\r
838 <simpara>\r
839 Use <emphasis>!</emphasis> to not make the corresponding negated long option available.\r
840 </simpara>\r
841 </listitem>\r
842 </itemizedlist>\r
843 </listitem>\r
844 </varlistentry>\r
845 </variablelist>\r
846 <simpara>The remainder of the line, after stripping the spaces, is used\r
847 as the help associated to the option.</simpara>\r
848 <simpara>Blank lines are ignored, and lines that don't match this specification are used\r
849 as option group headers (start the line with a space to create such\r
850 lines on purpose).</simpara>\r
851 </section>\r
852 <section id="_example">\r
853 <title>Example</title>\r
854 <screen>OPTS_SPEC="\\r
855 some-command [options] &lt;args&gt;...\r
857 some-command does foo and bar!\r
858 --\r
859 h,help    show the help\r
861 foo       some nifty option --foo\r
862 bar=      some cool option --bar with an argument\r
864   An option group Header\r
865 C?        option C with an optional argument"\r
867 eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"</screen>\r
868 </section>\r
869 </simplesect>\r
870 <simplesect id="_sq_quote">\r
871 <title>SQ-QUOTE</title>\r
872 <simpara>In <emphasis>--sq-quote</emphasis> mode, <emphasis>git rev-parse</emphasis> echoes on the standard output a\r
873 single line suitable for <emphasis>sh(1)</emphasis> <emphasis>eval</emphasis>. This line is made by\r
874 normalizing the arguments following <emphasis>--sq-quote</emphasis>. Nothing other than\r
875 quoting the arguments is done.</simpara>\r
876 <simpara>If you want command input to still be interpreted as usual by\r
877 <emphasis>git rev-parse</emphasis> before the output is shell quoted, see the <emphasis>--sq</emphasis>\r
878 option.</simpara>\r
879 <section id="_example_2">\r
880 <title>Example</title>\r
881 <screen>$ cat &gt;your-git-script.sh &lt;&lt;\EOF\r
882 #!/bin/sh\r
883 args=$(git rev-parse --sq-quote "$@")   # quote user-supplied arguments\r
884 command="git frotz -n24 $args"          # and use it inside a handcrafted\r
885                                         # command line\r
886 eval "$command"\r
887 EOF\r
889 $ sh your-git-script.sh "a b'c"</screen>\r
890 </section>\r
891 </simplesect>\r
892 <simplesect id="_examples">\r
893 <title>EXAMPLES</title>\r
894 <itemizedlist>\r
895 <listitem>\r
896 <simpara>\r
897 Print the object name of the current commit:\r
898 </simpara>\r
899 <screen>$ git rev-parse --verify HEAD</screen>\r
900 </listitem>\r
901 <listitem>\r
902 <simpara>\r
903 Print the commit object name from the revision in the $REV shell variable:\r
904 </simpara>\r
905 <screen>$ git rev-parse --verify $REV</screen>\r
906 <simpara>This will error out if $REV is empty or not a valid revision.</simpara>\r
907 </listitem>\r
908 <listitem>\r
909 <simpara>\r
910 Same as above:\r
911 </simpara>\r
912 <screen>$ git rev-parse --default master --verify $REV</screen>\r
913 <simpara>but if $REV is empty, the commit object name from master will be printed.</simpara>\r
914 </listitem>\r
915 </itemizedlist>\r
916 </simplesect>\r
917 <simplesect id="_git">\r
918 <title>GIT</title>\r
919 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
920 </simplesect>\r
921 </article>\r