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