Home Explore Blog CI



git

6th chunk of `Documentation/git-rev-parse.adoc`
b29191f1588c7084e0194634d2c138082e1dbfa6a24c5b890000000100000d9c
 `<opt-spec>`.

`<flags>`::
	`<flags>` are of `*`, `=`, `?` or `!`.
	* Use `=` if the option takes an argument.

	* Use `?` to mean that the option takes an optional argument. You
	  probably want to use the `--stuck-long` mode to be able to
	  unambiguously parse the optional argument.

	* Use `*` to mean that this option should not be listed in the usage
	  generated for the `-h` argument. It's shown for `--help-all` as
	  documented in linkgit:gitcli[7].

	* Use `!` to not make the corresponding negated long option available.

`<arg-hint>`::
	`<arg-hint>`, if specified, is used as a name of the argument in the
	help output, for options that take arguments. `<arg-hint>` is
	terminated by the first whitespace.  It is customary to use a
	dash to separate words in a multi-word argument hint.

The remainder of the line, after stripping the spaces, is used
as the help associated with the option.

Blank lines are ignored, and lines that don't match this specification are used
as option group headers (start the line with a space to create such
lines on purpose).

Example
~~~~~~~

------------
OPTS_SPEC="\
some-command [<options>] <args>...

some-command does foo and bar!
--
h,help!   show the help

foo       some nifty option --foo
bar=      some cool option --bar with an argument
baz=arg   another cool option --baz with a named argument
qux?path  qux may take a path argument but has meaning by itself

  An option group Header
C?        option C with an optional argument"

eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
------------


Usage text
~~~~~~~~~~

When `"$@"` is `-h` or `--help` in the above example, the following
usage text would be shown:

------------
usage: some-command [<options>] <args>...

    some-command does foo and bar!

    -h, --help            show the help
    --[no-]foo            some nifty option --foo
    --[no-]bar ...        some cool option --bar with an argument
    --[no-]baz <arg>      another cool option --baz with a named argument
    --[no-]qux[=<path>]   qux may take a path argument but has meaning by itself

An option group Header
    -C[...]               option C with an optional argument
------------

SQ-QUOTE
--------

In `--sq-quote` mode, 'git rev-parse' echoes on the standard output a
single line suitable for `sh(1)` `eval`. This line is made by
normalizing the arguments following `--sq-quote`. Nothing other than
quoting the arguments is done.

If you want command input to still be interpreted as usual by
'git rev-parse' before the output is shell quoted, see the `--sq`
option.

Example
~~~~~~~

------------
$ cat >your-git-script.sh <<\EOF
#!/bin/sh
args=$(git rev-parse --sq-quote "$@")   # quote user-supplied arguments
command="git frotz -n24 $args"          # and use it inside a handcrafted
					# command line
eval "$command"
EOF

$ sh your-git-script.sh "a b'c"
------------

EXAMPLES
--------

* Print the object name of the current commit:
+
------------
$ git rev-parse --verify HEAD
------------

* Print the commit object name from the revision in the $REV shell variable:
+
------------
$ git rev-parse --verify --end-of-options $REV^{commit}
------------
+
This will error out if $REV is empty or not a valid revision.

* Similar to above:
+
------------
$ git rev-parse --default master --verify --end-of-options $REV
------------
+
but if $REV is empty, the commit object name from master will be printed.

GIT
---
Part of the linkgit:git[1] suite

Title: Git Rev-Parse Options and Argument Quoting
Summary
The git rev-parse command provides options for parsing and normalizing command-line arguments, including the --parseopt mode for standardizing options and the --sq-quote mode for shell-quoting arguments, with various examples demonstrating their usage in shell scripts and command lines.