In git add how can you escape a leading "-" character in the filename? e.g.:
git add -index-apache-.html
gives:
error: unknown switch `d'
Thanks!
PS. same for
git checkout
In git add how can you escape a leading "-" character in the filename? e.g.:
git add -index-apache-.html
gives:
error: unknown switch `d'
Thanks!
PS. same for
git checkout
Use the --
to get around this issue. Anything past the double-dash is treated as just a filename.
This is more a Bash convention than a Git convention, as --
traditionally signifies the end of options.
A
--
signals the end of options and disables further option processing. Any arguments after the--
are treated as filenames and arguments. An argument of-
is equivalent to--
.
As an alternative to the general --
syntax,
git add -- -index-apache-.html
you could also use
git add ./-index-apache-.html
This works because the argument is a filename. Prepending ./
says "look for this file in the current directory", so it does not change the meaning of the filename (git would've looked there anyway), but it also means the argument no longer starts with -
and cannot be confused with option switches.