logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

git-rev-parse.1 (39503B)


  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 v1.79.2 <http://docbook.sf.net/>
  5. .\" Date: 2025-03-14
  6. .\" Manual: Git Manual
  7. .\" Source: Git 2.49.0
  8. .\" Language: English
  9. .\"
  10. .TH "GIT\-REV\-PARSE" "1" "2025-03-14" "Git 2\&.49\&.0" "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. .SH "DESCRIPTION"
  38. .sp
  39. 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"\&.
  40. .sp
  41. 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\&.
  42. .SH "OPTIONS"
  43. .SS "Operation Modes"
  44. .sp
  45. Each of these options must appear first on the command line\&.
  46. .PP
  47. \-\-parseopt
  48. .RS 4
  49. Use
  50. \fIgit rev\-parse\fR
  51. 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\&.
  52. .RE
  53. .PP
  54. \-\-sq\-quote
  55. .RS 4
  56. Use
  57. \fIgit rev\-parse\fR
  58. in shell quoting mode (see SQ\-QUOTE section below)\&. In contrast to the
  59. \fB\-\-sq\fR
  60. 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\&.
  61. .RE
  62. .SS "Options for \-\-parseopt"
  63. .PP
  64. \-\-keep\-dashdash
  65. .RS 4
  66. Only meaningful in
  67. \fB\-\-parseopt\fR
  68. mode\&. Tells the option parser to echo out the first
  69. \fB\-\-\fR
  70. met instead of skipping it\&.
  71. .RE
  72. .PP
  73. \-\-stop\-at\-non\-option
  74. .RS 4
  75. Only meaningful in
  76. \fB\-\-parseopt\fR
  77. mode\&. Lets the option parser stop at the first non\-option argument\&. This can be used to parse sub\-commands that take options themselves\&.
  78. .RE
  79. .PP
  80. \-\-stuck\-long
  81. .RS 4
  82. Only meaningful in
  83. \fB\-\-parseopt\fR
  84. mode\&. Output the options in their long form if available, and with their arguments stuck\&.
  85. .RE
  86. .SS "Options for Filtering"
  87. .PP
  88. \-\-revs\-only
  89. .RS 4
  90. Do not output flags and parameters not meant for
  91. \fIgit rev\-list\fR
  92. command\&.
  93. .RE
  94. .PP
  95. \-\-no\-revs
  96. .RS 4
  97. Do not output flags and parameters meant for
  98. \fIgit rev\-list\fR
  99. command\&.
  100. .RE
  101. .PP
  102. \-\-flags
  103. .RS 4
  104. Do not output non\-flag parameters\&.
  105. .RE
  106. .PP
  107. \-\-no\-flags
  108. .RS 4
  109. Do not output flag parameters\&.
  110. .RE
  111. .SS "Options for Output"
  112. .PP
  113. \-\-default <arg>
  114. .RS 4
  115. If there is no parameter given by the user, use
  116. \fI<arg>\fR
  117. instead\&.
  118. .RE
  119. .PP
  120. \-\-prefix <arg>
  121. .RS 4
  122. Behave as if
  123. \fIgit rev\-parse\fR
  124. was invoked from the
  125. \fI<arg>\fR
  126. subdirectory of the working tree\&. Any relative filenames are resolved as if they are prefixed by
  127. \fI<arg>\fR
  128. and will be printed in that form\&.
  129. .sp
  130. 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:
  131. .sp
  132. .if n \{\
  133. .RS 4
  134. .\}
  135. .nf
  136. prefix=$(git rev\-parse \-\-show\-prefix)
  137. cd "$(git rev\-parse \-\-show\-toplevel)"
  138. # rev\-parse provides the \-\- needed for \*(Aqset\*(Aq
  139. eval "set $(git rev\-parse \-\-sq \-\-prefix "$prefix" \-\- "$@")"
  140. .fi
  141. .if n \{\
  142. .RE
  143. .\}
  144. .RE
  145. .PP
  146. \-\-verify
  147. .RS 4
  148. 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\&.
  149. .sp
  150. 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
  151. \fB^\fR{type} peeling operator to the parameter\&. For example,
  152. \fBgit\fR
  153. \fBrev\-parse\fR
  154. "$VAR^{commit}" will make sure
  155. \fB$VAR\fR
  156. 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
  157. \fB$VAR\fR
  158. names an existing object of any type,
  159. \fBgit\fR
  160. \fBrev\-parse\fR
  161. "$VAR^{object}" can be used\&.
  162. .sp
  163. Note that if you are verifying a name from an untrusted source, it is wise to use
  164. \fB\-\-end\-of\-options\fR
  165. so that the name argument is not mistaken for another option\&.
  166. .RE
  167. .PP
  168. \-q, \-\-quiet
  169. .RS 4
  170. Only meaningful in
  171. \fB\-\-verify\fR
  172. 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\&.
  173. .RE
  174. .PP
  175. \-\-sq
  176. .RS 4
  177. 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
  178. \fB\-S\fR
  179. with
  180. \fIgit diff\-*\fR)\&. In contrast to the
  181. \fB\-\-sq\-quote\fR
  182. option, the command input is still interpreted as usual\&.
  183. .RE
  184. .PP
  185. \-\-short[=<length>]
  186. .RS 4
  187. Same as
  188. \fB\-\-verify\fR
  189. but shortens the object name to a unique prefix with at least
  190. \fBlength\fR
  191. characters\&. The minimum length is 4, the default is the effective value of the
  192. \fBcore\&.abbrev\fR
  193. configuration variable (see
  194. \fBgit-config\fR(1))\&.
  195. .RE
  196. .PP
  197. \-\-not
  198. .RS 4
  199. When showing object names, prefix them with
  200. \fI^\fR
  201. and strip
  202. \fI^\fR
  203. prefix from the object names that already have one\&.
  204. .RE
  205. .PP
  206. \-\-abbrev\-ref[=(strict|loose)]
  207. .RS 4
  208. A non\-ambiguous short name of the objects name\&. The option core\&.warnAmbiguousRefs is used to select the strict abbreviation mode\&.
  209. .RE
  210. .PP
  211. \-\-symbolic
  212. .RS 4
  213. Usually the object names are output in SHA\-1 form (with possible
  214. \fI^\fR
  215. prefix); this option makes them output in a form as close to the original input as possible\&.
  216. .RE
  217. .PP
  218. \-\-symbolic\-full\-name
  219. .RS 4
  220. 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")\&.
  221. .RE
  222. .PP
  223. \-\-output\-object\-format=(sha1|sha256|storage)
  224. .RS 4
  225. Allow oids to be input from any object format that the current repository supports\&.
  226. .sp
  227. .if n \{\
  228. .RS 4
  229. .\}
  230. .nf
  231. Specifying "sha1" translates if necessary and returns a sha1 oid\&.
  232. .fi
  233. .if n \{\
  234. .RE
  235. .\}
  236. .sp
  237. .if n \{\
  238. .RS 4
  239. .\}
  240. .nf
  241. Specifying "sha256" translates if necessary and returns a sha256 oid\&.
  242. .fi
  243. .if n \{\
  244. .RE
  245. .\}
  246. .sp
  247. .if n \{\
  248. .RS 4
  249. .\}
  250. .nf
  251. Specifying "storage" translates if necessary and returns an oid in
  252. encoded in the storage hash algorithm\&.
  253. .fi
  254. .if n \{\
  255. .RE
  256. .\}
  257. .RE
  258. .SS "Options for Objects"
  259. .PP
  260. \-\-all
  261. .RS 4
  262. Show all refs found in
  263. \fBrefs/\fR\&.
  264. .RE
  265. .PP
  266. \-\-branches[=<pattern>], \-\-tags[=<pattern>], \-\-remotes[=<pattern>]
  267. .RS 4
  268. Show all branches, tags, or remote\-tracking branches, respectively (i\&.e\&., refs found in
  269. \fBrefs/heads\fR,
  270. \fBrefs/tags\fR, or
  271. \fBrefs/remotes\fR, respectively)\&.
  272. .sp
  273. If a
  274. \fBpattern\fR
  275. is given, only refs matching the given shell glob are shown\&. If the pattern does not contain a globbing character (?, *, or [), it is turned into a prefix match by appending
  276. \fB/\fR*\&.
  277. .RE
  278. .PP
  279. \-\-glob=<pattern>
  280. .RS 4
  281. Show all refs matching the shell glob pattern
  282. \fBpattern\fR\&. If the pattern does not start with
  283. \fBrefs/\fR, this is automatically prepended\&. If the pattern does not contain a globbing character (?, *, or [), it is turned into a prefix match by appending
  284. \fB/\fR*\&.
  285. .RE
  286. .PP
  287. \-\-exclude=<glob\-pattern>
  288. .RS 4
  289. Do not include refs matching
  290. \fI<glob\-pattern>\fR
  291. that the next
  292. \fB\-\-all\fR,
  293. \fB\-\-branches\fR,
  294. \fB\-\-tags\fR,
  295. \fB\-\-remotes\fR, or
  296. \fB\-\-glob\fR
  297. would otherwise consider\&. Repetitions of this option accumulate exclusion patterns up to the next
  298. \fB\-\-all\fR,
  299. \fB\-\-branches\fR,
  300. \fB\-\-tags\fR,
  301. \fB\-\-remotes\fR, or
  302. \fB\-\-glob\fR
  303. option (other options or arguments do not clear accumulated patterns)\&.
  304. .sp
  305. The patterns given should not begin with
  306. \fBrefs/heads\fR,
  307. \fBrefs/tags\fR, or
  308. \fBrefs/remotes\fR
  309. when applied to
  310. \fB\-\-branches\fR,
  311. \fB\-\-tags\fR, or
  312. \fB\-\-remotes\fR, respectively, and they must begin with
  313. \fBrefs/\fR
  314. when applied to
  315. \fB\-\-glob\fR
  316. or
  317. \fB\-\-all\fR\&. If a trailing
  318. \fI/*\fR
  319. is intended, it must be given explicitly\&.
  320. .RE
  321. .PP
  322. \-\-exclude\-hidden=(fetch|receive|uploadpack)
  323. .RS 4
  324. Do not include refs that would be hidden by
  325. \fBgit\-fetch\fR,
  326. \fBgit\-receive\-pack\fR
  327. or
  328. \fBgit\-upload\-pack\fR
  329. by consulting the appropriate
  330. \fBfetch\&.hideRefs\fR,
  331. \fBreceive\&.hideRefs\fR
  332. or
  333. \fBuploadpack\&.hideRefs\fR
  334. configuration along with
  335. \fBtransfer\&.hideRefs\fR
  336. (see
  337. \fBgit-config\fR(1))\&. This option affects the next pseudo\-ref option
  338. \fB\-\-all\fR
  339. or
  340. \fB\-\-glob\fR
  341. and is cleared after processing them\&.
  342. .RE
  343. .PP
  344. \-\-disambiguate=<prefix>
  345. .RS 4
  346. 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\&.
  347. .RE
  348. .SS "Options for Files"
  349. .PP
  350. \-\-local\-env\-vars
  351. .RS 4
  352. 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\&.
  353. .RE
  354. .PP
  355. \-\-path\-format=(absolute|relative)
  356. .RS 4
  357. 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\&.
  358. .sp
  359. 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\&.
  360. .RE
  361. .sp
  362. The following options are modified by \fB\-\-path\-format\fR:
  363. .PP
  364. \-\-git\-dir
  365. .RS 4
  366. Show
  367. \fB$GIT_DIR\fR
  368. if defined\&. Otherwise show the path to the \&.git directory\&. The path shown, when relative, is relative to the current working directory\&.
  369. .sp
  370. If
  371. \fB$GIT_DIR\fR
  372. 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\&.
  373. .RE
  374. .PP
  375. \-\-git\-common\-dir
  376. .RS 4
  377. Show
  378. \fB$GIT_COMMON_DIR\fR
  379. if defined, else
  380. \fB$GIT_DIR\fR\&.
  381. .RE
  382. .PP
  383. \-\-resolve\-git\-dir <path>
  384. .RS 4
  385. 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\&.
  386. .RE
  387. .PP
  388. \-\-git\-path <path>
  389. .RS 4
  390. 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\&.
  391. .RE
  392. .PP
  393. \-\-show\-toplevel
  394. .RS 4
  395. Show the (by default, absolute) path of the top\-level directory of the working tree\&. If there is no working tree, report an error\&.
  396. .RE
  397. .PP
  398. \-\-show\-superproject\-working\-tree
  399. .RS 4
  400. 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\&.
  401. .RE
  402. .PP
  403. \-\-shared\-index\-path
  404. .RS 4
  405. Show the path to the shared index file in split index mode, or empty if not in split\-index mode\&.
  406. .RE
  407. .sp
  408. The following options are unaffected by \fB\-\-path\-format\fR:
  409. .PP
  410. \-\-absolute\-git\-dir
  411. .RS 4
  412. Like
  413. \fB\-\-git\-dir\fR, but its output is always the canonicalized absolute path\&.
  414. .RE
  415. .PP
  416. \-\-is\-inside\-git\-dir
  417. .RS 4
  418. When the current working directory is below the repository directory print "true", otherwise "false"\&.
  419. .RE
  420. .PP
  421. \-\-is\-inside\-work\-tree
  422. .RS 4
  423. When the current working directory is inside the work tree of the repository print "true", otherwise "false"\&.
  424. .RE
  425. .PP
  426. \-\-is\-bare\-repository
  427. .RS 4
  428. When the repository is bare print "true", otherwise "false"\&.
  429. .RE
  430. .PP
  431. \-\-is\-shallow\-repository
  432. .RS 4
  433. When the repository is shallow print "true", otherwise "false"\&.
  434. .RE
  435. .PP
  436. \-\-show\-cdup
  437. .RS 4
  438. 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)\&.
  439. .RE
  440. .PP
  441. \-\-show\-prefix
  442. .RS 4
  443. When the command is invoked from a subdirectory, show the path of the current directory relative to the top\-level directory\&.
  444. .RE
  445. .PP
  446. \-\-show\-object\-format[=(storage|input|output)]
  447. .RS 4
  448. Show the object format (hash algorithm) used for the repository for storage inside the \&.\fBgit\fR
  449. directory, input, or output\&. For input, multiple algorithms may be printed, space\-separated\&. If not specified, the default is "storage"\&.
  450. .RE
  451. .PP
  452. \-\-show\-ref\-format
  453. .RS 4
  454. Show the reference storage format used for the repository\&.
  455. .RE
  456. .SS "Other Options"
  457. .PP
  458. \-\-since=<datestring>, \-\-after=<datestring>
  459. .RS 4
  460. Parse the date string, and output the corresponding \-\-max\-age= parameter for
  461. \fIgit rev\-list\fR\&.
  462. .RE
  463. .PP
  464. \-\-until=<datestring>, \-\-before=<datestring>
  465. .RS 4
  466. Parse the date string, and output the corresponding \-\-min\-age= parameter for
  467. \fIgit rev\-list\fR\&.
  468. .RE
  469. .PP
  470. <arg>\&...\:
  471. .RS 4
  472. Flags and parameters to be parsed\&.
  473. .RE
  474. .SH "SPECIFYING REVISIONS"
  475. .sp
  476. 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\&.
  477. .if n \{\
  478. .sp
  479. .\}
  480. .RS 4
  481. .it 1 an-trap
  482. .nr an-no-space-flag 1
  483. .nr an-break-flag 1
  484. .br
  485. .ps +1
  486. \fBNote\fR
  487. .ps -1
  488. .br
  489. .sp
  490. 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\&.
  491. .sp .5v
  492. .RE
  493. .PP
  494. \fI<sha1>\fR, e\&.g\&. \fIdae86e1950b1277e545cee180551750029cfe735\fR, \fIdae86e\fR
  495. .RS 4
  496. 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\&.
  497. .RE
  498. .PP
  499. \fI<describeOutput>\fR, e\&.g\&. \fIv1\&.7\&.4\&.2\-679\-g3bee7fb\fR
  500. .RS 4
  501. Output from
  502. \fBgit\fR
  503. \fBdescribe\fR; i\&.e\&. a closest tag, optionally followed by a dash and a number of commits, followed by a dash, a
  504. \fIg\fR, and an abbreviated object name\&.
  505. .RE
  506. .PP
  507. \fI<refname>\fR, e\&.g\&. \fImaster\fR, \fIheads/master\fR, \fIrefs/heads/master\fR
  508. .RS 4
  509. A symbolic ref name\&. E\&.g\&.
  510. \fImaster\fR
  511. typically means the commit object referenced by
  512. \fIrefs/heads/master\fR\&. If you happen to have both
  513. \fIheads/master\fR
  514. and
  515. \fItags/master\fR, you can explicitly say
  516. \fIheads/master\fR
  517. to tell Git which one you mean\&. When ambiguous, a
  518. \fI<refname>\fR
  519. is disambiguated by taking the first match in the following rules:
  520. .sp
  521. .RS 4
  522. .ie n \{\
  523. \h'-04' 1.\h'+01'\c
  524. .\}
  525. .el \{\
  526. .sp -1
  527. .IP " 1." 4.2
  528. .\}
  529. If
  530. \fI$GIT_DIR/<refname>\fR
  531. exists, that is what you mean (this is usually useful only for
  532. \fBHEAD\fR,
  533. \fBFETCH_HEAD\fR,
  534. \fBORIG_HEAD\fR,
  535. \fBMERGE_HEAD\fR,
  536. \fBREBASE_HEAD\fR,
  537. \fBREVERT_HEAD\fR,
  538. \fBCHERRY_PICK_HEAD\fR,
  539. \fBBISECT_HEAD\fR
  540. and
  541. \fBAUTO_MERGE\fR);
  542. .RE
  543. .sp
  544. .RS 4
  545. .ie n \{\
  546. \h'-04' 2.\h'+01'\c
  547. .\}
  548. .el \{\
  549. .sp -1
  550. .IP " 2." 4.2
  551. .\}
  552. otherwise,
  553. \fIrefs/<refname>\fR
  554. if it exists;
  555. .RE
  556. .sp
  557. .RS 4
  558. .ie n \{\
  559. \h'-04' 3.\h'+01'\c
  560. .\}
  561. .el \{\
  562. .sp -1
  563. .IP " 3." 4.2
  564. .\}
  565. otherwise,
  566. \fIrefs/tags/<refname>\fR
  567. if it exists;
  568. .RE
  569. .sp
  570. .RS 4
  571. .ie n \{\
  572. \h'-04' 4.\h'+01'\c
  573. .\}
  574. .el \{\
  575. .sp -1
  576. .IP " 4." 4.2
  577. .\}
  578. otherwise,
  579. \fIrefs/heads/<refname>\fR
  580. if it exists;
  581. .RE
  582. .sp
  583. .RS 4
  584. .ie n \{\
  585. \h'-04' 5.\h'+01'\c
  586. .\}
  587. .el \{\
  588. .sp -1
  589. .IP " 5." 4.2
  590. .\}
  591. otherwise,
  592. \fIrefs/remotes/<refname>\fR
  593. if it exists;
  594. .RE
  595. .sp
  596. .RS 4
  597. .ie n \{\
  598. \h'-04' 6.\h'+01'\c
  599. .\}
  600. .el \{\
  601. .sp -1
  602. .IP " 6." 4.2
  603. .\}
  604. otherwise,
  605. \fIrefs/remotes/<refname>/HEAD\fR
  606. if it exists\&.
  607. .PP
  608. \fBHEAD\fR
  609. .RS 4
  610. names the commit on which you based the changes in the working tree\&.
  611. .RE
  612. .PP
  613. \fBFETCH_HEAD\fR
  614. .RS 4
  615. records the branch which you fetched from a remote repository with your last
  616. \fBgit\fR
  617. \fBfetch\fR
  618. invocation\&.
  619. .RE
  620. .PP
  621. \fBORIG_HEAD\fR
  622. .RS 4
  623. is created by commands that move your
  624. \fBHEAD\fR
  625. in a drastic way (\fBgit\fR
  626. \fBam\fR,
  627. \fBgit\fR
  628. \fBmerge\fR,
  629. \fBgit\fR
  630. \fBrebase\fR,
  631. \fBgit\fR
  632. \fBreset\fR), to record the position of the
  633. \fBHEAD\fR
  634. before their operation, so that you can easily change the tip of the branch back to the state before you ran them\&.
  635. .RE
  636. .PP
  637. \fBMERGE_HEAD\fR
  638. .RS 4
  639. records the commit(s) which you are merging into your branch when you run
  640. \fBgit\fR
  641. \fBmerge\fR\&.
  642. .RE
  643. .PP
  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\&.
  649. .RE
  650. .PP
  651. \fBREVERT_HEAD\fR
  652. .RS 4
  653. records the commit which you are reverting when you run
  654. \fBgit\fR
  655. \fBrevert\fR\&.
  656. .RE
  657. .PP
  658. \fBCHERRY_PICK_HEAD\fR
  659. .RS 4
  660. records the commit which you are cherry\-picking when you run
  661. \fBgit\fR
  662. \fBcherry\-pick\fR\&.
  663. .RE
  664. .PP
  665. \fBBISECT_HEAD\fR
  666. .RS 4
  667. records the current commit to be tested when you run
  668. \fBgit\fR
  669. \fBbisect\fR
  670. \fB\-\-no\-checkout\fR\&.
  671. .RE
  672. .PP
  673. \fBAUTO_MERGE\fR
  674. .RS 4
  675. records a tree object corresponding to the state the
  676. \fIort\fR
  677. merge strategy wrote to the working tree when a merge operation resulted in conflicts\&.
  678. .RE
  679. .RE
  680. .sp
  681. Note that any of the
  682. \fIrefs/*\fR
  683. cases above may come either from the
  684. \fB$GIT_DIR/refs\fR
  685. directory or from the
  686. \fB$GIT_DIR/packed\-refs\fR
  687. file\&. While the ref name encoding is unspecified, UTF\-8 is preferred as some output processing may assume ref names in UTF\-8\&.
  688. .RE
  689. .PP
  690. \fI@\fR
  691. .RS 4
  692. \fI@\fR
  693. alone is a shortcut for
  694. \fBHEAD\fR\&.
  695. .RE
  696. .PP
  697. \fI[<refname>]@{<date>}\fR, e\&.g\&. \fImaster@{yesterday}\fR, \fIHEAD@{5 minutes ago}\fR
  698. .RS 4
  699. A ref followed by the suffix
  700. \fI@\fR
  701. with a date specification enclosed in a brace pair (e\&.g\&.
  702. \fI{yesterday}\fR,
  703. \fI{1 month 2 weeks 3 days 1 hour 1 second ago}\fR
  704. or
  705. \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
  706. \fBlocal\fR
  707. ref at a given time; e\&.g\&., what was in your local
  708. \fImaster\fR
  709. branch last week\&. If you want to look at commits made during certain times, see
  710. \fB\-\-since\fR
  711. and
  712. \fB\-\-until\fR\&.
  713. .RE
  714. .PP
  715. \fI<refname>@{<n>}\fR, e\&.g\&. \fImaster@{1}\fR
  716. .RS 4
  717. A ref followed by the suffix
  718. \fI@\fR
  719. with an ordinal specification enclosed in a brace pair (e\&.g\&.
  720. \fI{1}\fR,
  721. \fI{15}\fR) specifies the n\-th prior value of that ref\&. For example
  722. \fImaster@{1}\fR
  723. is the immediate prior value of
  724. \fImaster\fR
  725. while
  726. \fImaster@{5}\fR
  727. is the 5th prior value of
  728. \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)\&.
  729. .RE
  730. .PP
  731. \fI@{<n>}\fR, e\&.g\&. \fI@{1}\fR
  732. .RS 4
  733. You can use the
  734. \fI@\fR
  735. construct with an empty ref part to get at a reflog entry of the current branch\&. For example, if you are on branch
  736. \fIblabla\fR
  737. then
  738. \fI@{1}\fR
  739. means the same as
  740. \fIblabla@{1}\fR\&.
  741. .RE
  742. .PP
  743. \fI@{\-<n>}\fR, e\&.g\&. \fI@{\-1}\fR
  744. .RS 4
  745. The construct
  746. \fI@{\-<n>}\fR
  747. means the <n>th branch/commit checked out before the current one\&.
  748. .RE
  749. .PP
  750. \fI[<branchname>]@{upstream}\fR, e\&.g\&. \fImaster@{upstream}\fR, \fI@{u}\fR
  751. .RS 4
  752. A branch B may be set up to build on top of a branch X (configured with
  753. \fBbranch\&.\fR\fI<name>\fR\fB\&.merge\fR) at a remote R (configured with
  754. \fBbranch\&.\fR\fI<name>\fR\fB\&.remote\fR)\&. B@{u} refers to the remote\-tracking branch for the branch X taken from remote R, typically found at
  755. \fBrefs/remotes/R/X\fR\&.
  756. .RE
  757. .PP
  758. \fI[<branchname>]@{push}\fR, e\&.g\&. \fImaster@{push}\fR, \fI@{push}\fR
  759. .RS 4
  760. The suffix
  761. \fI@{push}\fR
  762. reports the branch "where we would push to" if
  763. \fBgit\fR
  764. \fBpush\fR
  765. were run while
  766. \fBbranchname\fR
  767. was checked out (or the current
  768. \fBHEAD\fR
  769. if no branchname is specified)\&. Like for
  770. \fI@{upstream}\fR, we report the remote\-tracking branch that corresponds to that branch at the remote\&.
  771. .sp
  772. Here\(cqs an example to make it more clear:
  773. .sp
  774. .if n \{\
  775. .RS 4
  776. .\}
  777. .nf
  778. $ git config push\&.default current
  779. $ git config remote\&.pushdefault myfork
  780. $ git switch \-c mybranch origin/master
  781. $ git rev\-parse \-\-symbolic\-full\-name @{upstream}
  782. refs/remotes/origin/master
  783. $ git rev\-parse \-\-symbolic\-full\-name @{push}
  784. refs/remotes/myfork/mybranch
  785. .fi
  786. .if n \{\
  787. .RE
  788. .\}
  789. .sp
  790. 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,
  791. \fI@{push}\fR
  792. is the same as
  793. \fI@{upstream}\fR, and there is no need for it\&.
  794. .sp
  795. This suffix is also accepted when spelled in uppercase, and means the same thing no matter the case\&.
  796. .RE
  797. .PP
  798. \fI<rev>^[<n>]\fR, e\&.g\&. \fIHEAD^, v1\&.5\&.1^0\fR
  799. .RS 4
  800. A suffix
  801. \fI^\fR
  802. to a revision parameter means the first parent of that commit object\&.
  803. \fI^<n>\fR
  804. means the <n>th parent (i\&.e\&.
  805. \fI<rev>^\fR
  806. is equivalent to
  807. \fI<rev>^1\fR)\&. As a special rule,
  808. \fI<rev>^0\fR
  809. means the commit itself and is used when
  810. \fI<rev>\fR
  811. is the object name of a tag object that refers to a commit object\&.
  812. .RE
  813. .PP
  814. \fI<rev>~[<n>]\fR, e\&.g\&. \fIHEAD~, master~3\fR
  815. .RS 4
  816. A suffix
  817. \fI~\fR
  818. to a revision parameter means the first parent of that commit object\&. A suffix
  819. \fI~<n>\fR
  820. 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\&.
  821. \fI<rev>~3\fR
  822. is equivalent to
  823. \fI<rev>^^^\fR
  824. which is equivalent to
  825. \fI<rev>^1^1^1\fR\&. See below for an illustration of the usage of this form\&.
  826. .RE
  827. .PP
  828. \fI<rev>^{<type>}\fR, e\&.g\&. \fIv0\&.99\&.8^{commit}\fR
  829. .RS 4
  830. A suffix
  831. \fI^\fR
  832. followed by an object type name enclosed in brace pair means dereference the object at
  833. \fI<rev>\fR
  834. recursively until an object of type
  835. \fI<type>\fR
  836. is found or the object cannot be dereferenced anymore (in which case, barf)\&. For example, if
  837. \fI<rev>\fR
  838. is a commit\-ish,
  839. \fI<rev>^{commit}\fR
  840. describes the corresponding commit object\&. Similarly, if
  841. \fI<rev>\fR
  842. is a tree\-ish,
  843. \fI<rev>^{tree}\fR
  844. describes the corresponding tree object\&.
  845. \fI<rev>^0\fR
  846. is a short\-hand for
  847. \fI<rev>^{commit}\fR\&.
  848. .sp
  849. \fI<rev>^{object}\fR
  850. can be used to make sure
  851. \fI<rev>\fR
  852. names an object that exists, without requiring
  853. \fI<rev>\fR
  854. to be a tag, and without dereferencing
  855. \fI<rev>\fR; because a tag is already an object, it does not have to be dereferenced even once to get to an object\&.
  856. .sp
  857. \fI<rev>^{tag}\fR
  858. can be used to ensure that
  859. \fI<rev>\fR
  860. identifies an existing tag object\&.
  861. .RE
  862. .PP
  863. \fI<rev>^{}\fR, e\&.g\&. \fIv0\&.99\&.8^{}\fR
  864. .RS 4
  865. A suffix
  866. \fI^\fR
  867. 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\&.
  868. .RE
  869. .PP
  870. \fI<rev>^{/<text>}\fR, e\&.g\&. \fIHEAD^{/fix nasty bug}\fR
  871. .RS 4
  872. A suffix
  873. \fI^\fR
  874. to a revision parameter, followed by a brace pair that contains a text led by a slash, is the same as the
  875. \fI:/fix nasty bug\fR
  876. syntax below except that it returns the youngest matching commit which is reachable from the
  877. \fI<rev>\fR
  878. before
  879. \fI^\fR\&.
  880. .RE
  881. .PP
  882. \fI:/<text>\fR, e\&.g\&. \fI:/fix nasty bug\fR
  883. .RS 4
  884. 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\&.
  885. \fI:/^foo\fR\&. The special sequence
  886. \fI:/!\fR
  887. is reserved for modifiers to what is matched\&.
  888. \fI:/!\-foo\fR
  889. performs a negative match, while
  890. \fI:/!!foo\fR
  891. matches a literal
  892. \fI!\fR
  893. character, followed by
  894. \fIfoo\fR\&. Any other sequence beginning with
  895. \fI:/!\fR
  896. is reserved for now\&. Depending on the given text, the shell\(cqs word splitting rules might require additional quoting\&.
  897. .RE
  898. .PP
  899. \fI<rev>:<path>\fR, e\&.g\&. \fIHEAD:README\fR, \fImaster:\&./README\fR
  900. .RS 4
  901. A suffix
  902. \fI:\fR
  903. 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
  904. \fI\&./\fR
  905. or
  906. \fI\&.\&./\fR
  907. 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\&.
  908. .RE
  909. .PP
  910. \fI:[<n>:]<path>\fR, e\&.g\&. \fI:0:README\fR, \fI:README\fR
  911. .RS 4
  912. 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\&.
  913. .RE
  914. .sp
  915. 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\&.
  916. .sp
  917. .if n \{\
  918. .RS 4
  919. .\}
  920. .nf
  921. G H I J
  922. \e / \e /
  923. D E F
  924. \e | / \e
  925. \e | / |
  926. \e|/ |
  927. B C
  928. \e /
  929. \e /
  930. A
  931. .fi
  932. .if n \{\
  933. .RE
  934. .\}
  935. .sp
  936. .if n \{\
  937. .RS 4
  938. .\}
  939. .nf
  940. A = = A^0
  941. B = A^ = A^1 = A~1
  942. C = = A^2
  943. D = A^^ = A^1^1 = A~2
  944. E = B^2 = A^^2
  945. F = B^3 = A^^3
  946. G = A^^^ = A^1^1^1 = A~3
  947. H = D^2 = B^^2 = A^^^2 = A~2^2
  948. I = F^ = B^3^ = A^^3^
  949. J = F^2 = B^3^2 = A^^3^2
  950. .fi
  951. .if n \{\
  952. .RE
  953. .\}
  954. .SH "SPECIFYING RANGES"
  955. .sp
  956. History traversing commands such as \fBgit\fR \fBlog\fR operate on a set of commits, not just a single commit\&.
  957. .sp
  958. 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\&.
  959. .sp
  960. Specifying several revisions means the set of commits reachable from any of the given commits\&.
  961. .sp
  962. A commit\(cqs reachable set is the commit itself and the commits in its ancestry chain\&.
  963. .sp
  964. There are several notations to specify a set of connected commits (called a "revision range"), illustrated below\&.
  965. .SS "Commit Exclusions"
  966. .PP
  967. \fI^<rev>\fR (caret) Notation
  968. .RS 4
  969. To exclude commits reachable from a commit, a prefix
  970. \fI^\fR
  971. notation is used\&. E\&.g\&.
  972. \fI^r1 r2\fR
  973. means commits reachable from
  974. \fIr2\fR
  975. but exclude the ones reachable from
  976. \fIr1\fR
  977. (i\&.e\&.
  978. \fIr1\fR
  979. and its ancestors)\&.
  980. .RE
  981. .SS "Dotted Range Notations"
  982. .PP
  983. The \fI\&.\&.\fR (two\-dot) Range Notation
  984. .RS 4
  985. The
  986. \fI^r1 r2\fR
  987. set operation appears so often that there is a shorthand for it\&. When you have two commits
  988. \fIr1\fR
  989. and
  990. \fIr2\fR
  991. (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
  992. \fI^r1 r2\fR
  993. and it can be written as
  994. \fIr1\&.\&.r2\fR\&.
  995. .RE
  996. .PP
  997. The \fI\&.\&.\&.\fR (three\-dot) Symmetric Difference Notation
  998. .RS 4
  999. A similar notation
  1000. \fIr1\&.\&.\&.r2\fR
  1001. is called symmetric difference of
  1002. \fIr1\fR
  1003. and
  1004. \fIr2\fR
  1005. and is defined as
  1006. \fIr1 r2 \-\-not $(git merge\-base \-\-all r1 r2)\fR\&. It is the set of commits that are reachable from either one of
  1007. \fIr1\fR
  1008. (left side) or
  1009. \fIr2\fR
  1010. (right side) but not from both\&.
  1011. .RE
  1012. .sp
  1013. 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\&.
  1014. .sp
  1015. 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\&.
  1016. .sp
  1017. .if n \{\
  1018. .RS 4
  1019. .\}
  1020. .nf
  1021. $ git log A\&.\&.B C\&.\&.D
  1022. .fi
  1023. .if n \{\
  1024. .RE
  1025. .\}
  1026. .sp
  1027. 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:
  1028. .sp
  1029. .if n \{\
  1030. .RS 4
  1031. .\}
  1032. .nf
  1033. \-\-\-A\-\-\-B\-\-\-o\-\-\-o\-\-\-C\-\-\-D
  1034. .fi
  1035. .if n \{\
  1036. .RE
  1037. .\}
  1038. .sp
  1039. because A and B are reachable from C, the revision range specified by these two dotted ranges is a single commit D\&.
  1040. .SS "Other <rev>^ Parent Shorthand Notations"
  1041. .sp
  1042. Three other shorthands exist, particularly useful for merge commits, for naming a set that is formed by a commit and its parent commits\&.
  1043. .sp
  1044. The \fIr1^@\fR notation means all parents of \fIr1\fR\&.
  1045. .sp
  1046. The \fIr1^!\fR notation includes commit \fIr1\fR but excludes all of its parents\&. By itself, this notation denotes the single commit \fIr1\fR\&.
  1047. .sp
  1048. 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)\&.
  1049. .sp
  1050. 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\&.
  1051. .SH "REVISION RANGE SUMMARY"
  1052. .PP
  1053. \fI<rev>\fR
  1054. .RS 4
  1055. Include commits that are reachable from <rev> (i\&.e\&. <rev> and its ancestors)\&.
  1056. .RE
  1057. .PP
  1058. \fI^<rev>\fR
  1059. .RS 4
  1060. Exclude commits that are reachable from <rev> (i\&.e\&. <rev> and its ancestors)\&.
  1061. .RE
  1062. .PP
  1063. \fI<rev1>\&.\&.<rev2>\fR
  1064. .RS 4
  1065. 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
  1066. \fBHEAD\fR\&.
  1067. .RE
  1068. .PP
  1069. \fI<rev1>\&.\&.\&.<rev2>\fR
  1070. .RS 4
  1071. 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
  1072. \fBHEAD\fR\&.
  1073. .RE
  1074. .PP
  1075. \fI<rev>^@\fR, e\&.g\&. \fIHEAD^@\fR
  1076. .RS 4
  1077. A suffix
  1078. \fI^\fR
  1079. followed by an at sign is the same as listing all parents of
  1080. \fI<rev>\fR
  1081. (meaning, include anything reachable from its parents, but not the commit itself)\&.
  1082. .RE
  1083. .PP
  1084. \fI<rev>^!\fR, e\&.g\&. \fIHEAD^!\fR
  1085. .RS 4
  1086. A suffix
  1087. \fI^\fR
  1088. followed by an exclamation mark is the same as giving commit
  1089. \fI<rev>\fR
  1090. and all its parents prefixed with
  1091. \fI^\fR
  1092. to exclude them (and their ancestors)\&.
  1093. .RE
  1094. .PP
  1095. \fI<rev>^\-<n>\fR, e\&.g\&. \fIHEAD^\-, HEAD^\-2\fR
  1096. .RS 4
  1097. Equivalent to
  1098. \fI<rev>^<n>\&.\&.<rev>\fR, with
  1099. \fI<n>\fR
  1100. = 1 if not given\&.
  1101. .RE
  1102. .sp
  1103. Here are a handful of examples using the Loeliger illustration above, with each step in the notation\(cqs expansion and selection carefully spelt out:
  1104. .sp
  1105. .if n \{\
  1106. .RS 4
  1107. .\}
  1108. .nf
  1109. Args Expanded arguments Selected commits
  1110. D G H D
  1111. D F G H I J D F
  1112. ^G D H D
  1113. ^D B E I J F B
  1114. ^D B C E I J F B C
  1115. C I J F C
  1116. B\&.\&.C = ^B C C
  1117. B\&.\&.\&.C = B ^F C G H D E B C
  1118. B^\- = B^\&.\&.B
  1119. = ^B^1 B E I J F B
  1120. C^@ = C^1
  1121. = F I J F
  1122. B^@ = B^1 B^2 B^3
  1123. = D E F D G H E F I J
  1124. C^! = C ^C^@
  1125. = C ^C^1
  1126. = C ^F C
  1127. B^! = B ^B^@
  1128. = B ^B^1 ^B^2 ^B^3
  1129. = B ^D ^E ^F B
  1130. F^! D = F ^I ^J D G H D F
  1131. .fi
  1132. .if n \{\
  1133. .RE
  1134. .\}
  1135. .SH "PARSEOPT"
  1136. .sp
  1137. 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\fR(\fB1\fR) does\&.
  1138. .sp
  1139. 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\fR(\fB1\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\&.
  1140. .sp
  1141. Note: Make sure you quote the result when passing it to \fBeval\fR\&. See below for an example\&.
  1142. .SS "Input Format"
  1143. .sp
  1144. \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\&.
  1145. .sp
  1146. Each line of options has this format:
  1147. .sp
  1148. .if n \{\
  1149. .RS 4
  1150. .\}
  1151. .nf
  1152. <opt\-spec><flags>*<arg\-hint>? SP+ help LF
  1153. .fi
  1154. .if n \{\
  1155. .RE
  1156. .\}
  1157. .PP
  1158. \fI<opt\-spec>\fR
  1159. .RS 4
  1160. 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
  1161. \fI<flags>\fR
  1162. characters\&.
  1163. \fBh,help\fR,
  1164. \fBdry\-run\fR
  1165. and
  1166. \fBf\fR
  1167. are examples of correct
  1168. \fI<opt\-spec>\fR\&.
  1169. .RE
  1170. .PP
  1171. \fI<flags>\fR
  1172. .RS 4
  1173. \fI<flags>\fR
  1174. are of *,
  1175. \fB=\fR, ? or !\&.
  1176. .sp
  1177. .RS 4
  1178. .ie n \{\
  1179. \h'-04'\(bu\h'+03'\c
  1180. .\}
  1181. .el \{\
  1182. .sp -1
  1183. .IP \(bu 2.3
  1184. .\}
  1185. Use
  1186. \fB=\fR
  1187. if the option takes an argument\&.
  1188. .RE
  1189. .sp
  1190. .RS 4
  1191. .ie n \{\
  1192. \h'-04'\(bu\h'+03'\c
  1193. .\}
  1194. .el \{\
  1195. .sp -1
  1196. .IP \(bu 2.3
  1197. .\}
  1198. Use ? to mean that the option takes an optional argument\&. You probably want to use the
  1199. \fB\-\-stuck\-long\fR
  1200. mode to be able to unambiguously parse the optional argument\&.
  1201. .RE
  1202. .sp
  1203. .RS 4
  1204. .ie n \{\
  1205. \h'-04'\(bu\h'+03'\c
  1206. .\}
  1207. .el \{\
  1208. .sp -1
  1209. .IP \(bu 2.3
  1210. .\}
  1211. Use * to mean that this option should not be listed in the usage generated for the
  1212. \fB\-h\fR
  1213. argument\&. It\(cqs shown for
  1214. \fB\-\-help\-all\fR
  1215. as documented in
  1216. \fBgitcli\fR(7)\&.
  1217. .RE
  1218. .sp
  1219. .RS 4
  1220. .ie n \{\
  1221. \h'-04'\(bu\h'+03'\c
  1222. .\}
  1223. .el \{\
  1224. .sp -1
  1225. .IP \(bu 2.3
  1226. .\}
  1227. Use ! to not make the corresponding negated long option available\&.
  1228. .RE
  1229. .RE
  1230. .PP
  1231. \fI<arg\-hint>\fR
  1232. .RS 4
  1233. \fI<arg\-hint>\fR, if specified, is used as a name of the argument in the help output, for options that take arguments\&.
  1234. \fI<arg\-hint>\fR
  1235. is terminated by the first whitespace\&. It is customary to use a dash to separate words in a multi\-word argument hint\&.
  1236. .RE
  1237. .sp
  1238. The remainder of the line, after stripping the spaces, is used as the help associated with the option\&.
  1239. .sp
  1240. 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)\&.
  1241. .SS "Example"
  1242. .sp
  1243. .if n \{\
  1244. .RS 4
  1245. .\}
  1246. .nf
  1247. OPTS_SPEC="\e
  1248. some\-command [<options>] <args>\&.\&.\&.
  1249. some\-command does foo and bar!
  1250. \-\-
  1251. h,help! show the help
  1252. foo some nifty option \-\-foo
  1253. bar= some cool option \-\-bar with an argument
  1254. baz=arg another cool option \-\-baz with a named argument
  1255. qux?path qux may take a path argument but has meaning by itself
  1256. An option group Header
  1257. C? option C with an optional argument"
  1258. eval "$(echo "$OPTS_SPEC" | git rev\-parse \-\-parseopt \-\- "$@" || echo exit $?)"
  1259. .fi
  1260. .if n \{\
  1261. .RE
  1262. .\}
  1263. .SS "Usage text"
  1264. .sp
  1265. When "$@" is \fB\-h\fR or \fB\-\-help\fR in the above example, the following usage text would be shown:
  1266. .sp
  1267. .if n \{\
  1268. .RS 4
  1269. .\}
  1270. .nf
  1271. usage: some\-command [<options>] <args>\&.\&.\&.
  1272. some\-command does foo and bar!
  1273. \-h, \-\-help show the help
  1274. \-\-[no\-]foo some nifty option \-\-foo
  1275. \-\-[no\-]bar \&.\&.\&. some cool option \-\-bar with an argument
  1276. \-\-[no\-]baz <arg> another cool option \-\-baz with a named argument
  1277. \-\-[no\-]qux[=<path>] qux may take a path argument but has meaning by itself
  1278. An option group Header
  1279. \-C[\&.\&.\&.] option C with an optional argument
  1280. .fi
  1281. .if n \{\
  1282. .RE
  1283. .\}
  1284. .SH "SQ\-QUOTE"
  1285. .sp
  1286. In \fB\-\-sq\-quote\fR mode, \fIgit rev\-parse\fR echoes on the standard output a single line suitable for \fBsh\fR(\fB1\fR) \fBeval\fR\&. This line is made by normalizing the arguments following \fB\-\-sq\-quote\fR\&. Nothing other than quoting the arguments is done\&.
  1287. .sp
  1288. 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\&.
  1289. .SS "Example"
  1290. .sp
  1291. .if n \{\
  1292. .RS 4
  1293. .\}
  1294. .nf
  1295. $ cat >your\-git\-script\&.sh <<\eEOF
  1296. #!/bin/sh
  1297. args=$(git rev\-parse \-\-sq\-quote "$@") # quote user\-supplied arguments
  1298. command="git frotz \-n24 $args" # and use it inside a handcrafted
  1299. # command line
  1300. eval "$command"
  1301. EOF
  1302. $ sh your\-git\-script\&.sh "a b\*(Aqc"
  1303. .fi
  1304. .if n \{\
  1305. .RE
  1306. .\}
  1307. .SH "EXAMPLES"
  1308. .sp
  1309. .RS 4
  1310. .ie n \{\
  1311. \h'-04'\(bu\h'+03'\c
  1312. .\}
  1313. .el \{\
  1314. .sp -1
  1315. .IP \(bu 2.3
  1316. .\}
  1317. Print the object name of the current commit:
  1318. .sp
  1319. .if n \{\
  1320. .RS 4
  1321. .\}
  1322. .nf
  1323. $ git rev\-parse \-\-verify HEAD
  1324. .fi
  1325. .if n \{\
  1326. .RE
  1327. .\}
  1328. .RE
  1329. .sp
  1330. .RS 4
  1331. .ie n \{\
  1332. \h'-04'\(bu\h'+03'\c
  1333. .\}
  1334. .el \{\
  1335. .sp -1
  1336. .IP \(bu 2.3
  1337. .\}
  1338. Print the commit object name from the revision in the $REV shell variable:
  1339. .sp
  1340. .if n \{\
  1341. .RS 4
  1342. .\}
  1343. .nf
  1344. $ git rev\-parse \-\-verify \-\-end\-of\-options $REV^{commit}
  1345. .fi
  1346. .if n \{\
  1347. .RE
  1348. .\}
  1349. .sp
  1350. This will error out if $REV is empty or not a valid revision\&.
  1351. .RE
  1352. .sp
  1353. .RS 4
  1354. .ie n \{\
  1355. \h'-04'\(bu\h'+03'\c
  1356. .\}
  1357. .el \{\
  1358. .sp -1
  1359. .IP \(bu 2.3
  1360. .\}
  1361. Similar to above:
  1362. .sp
  1363. .if n \{\
  1364. .RS 4
  1365. .\}
  1366. .nf
  1367. $ git rev\-parse \-\-default master \-\-verify \-\-end\-of\-options $REV
  1368. .fi
  1369. .if n \{\
  1370. .RE
  1371. .\}
  1372. .sp
  1373. but if $REV is empty, the commit object name from master will be printed\&.
  1374. .RE
  1375. .SH "GIT"
  1376. .sp
  1377. Part of the \fBgit\fR(1) suite