Why does:
$ git log --pretty "format:%h %s"
fatal: invalid object name 'format'.
fail but both:
git log --pretty="format:%h %s"
git log --author bob
succeed? Why is the first line wrong? The first just looks like the third one, but it doesn't work.
That’s the inherent ambiguity of command-line options with optional values. --pretty
is one, unfortunately:
--pretty[=<format>]
[…] When
=<format>
part is omitted, it defaults tomedium
.
git log --pretty "format:%h %s"
treats format:%h %s
as a non-option argument (the revision range). git log --pretty="format:%h %s"
unambiguously gives --pretty
a value and has no non-option arguments.
According to man gitcli
(git version 2.46.1):
When a command-line option takes an argument, use the stuck form. In other words, write
git foo -oArg
instead ofgit foo -o Arg
for short options, andgit foo --long-opt=Arg
instead ofgit foo --long-opt Arg
for long options. An option that takes optional option-argument must be written in the stuck form.