git grep
seems to have simpler rules than regular GNU grep
, which will allow you to search for tabs and to escape special characters with a backslash. I am trying to find occurrences of the string ->upload
, and no way of escaping it seems to work.
How do I run git grep "->upload"
?
$ git grep ->upload
No output; return 0
$ git grep "->upload"
error: unknown switch `>'
git grep "\-\>upload"
No output; return error
$ git grep '->upload'
error: unknown switch `>'
When doubt, use a single-character class rather than a backslash to make a single character literal inside a regex:
git grep -e '-[>]upload'
Whereas the meaning of a backslash can be different depending on the specific character and the specific regex syntax in use, [>]
means the same thing consistently.
That said, the most immediate issue here isn't caused by the >
but by the leading dash, which makes the string indistinguishable from a list of options.
The -e
is needed not because of the >
, but because of the -
. Without it, ->upload
would be treated as a series of flags (->
, -u
, -p
, -l
, -o
, -a
, -d
).
That said, you can get away without the -e
by also moving the dash into a character class, thus making it no longer the first character on the command line:
git grep '[-][>]upload'
git grep -F -- '->upload'
Option -F
means: use fixed strings for patterns (don't interpret pattern as a regex).
--
separates options from arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With