Reputation: 738
The problem is that strings with two qoutes are searched well. But! I want to look for a string "Agent
(one double quote!) inside my repo on cmd in Windows. So I having this:
git grep "\"Agent\"" > 1.txt
(it works! all strings with "Agent"
was found)
git grep "\"Agent" > 1.txt
(error! fatal: ambiguous argument '>': unknown revision...
)
Any ideas how to properly escape?
Upvotes: 1
Views: 1143
Reputation: 626893
In Git CMD or Windows cmd console, you can use ^
to escape the "
inside the terminal:
git grep ""^""Agent" > 1.txt
In Git Bash, you can simply use
git grep '"Agent' > 1.txt
See this text I made on my data with "Regex
pattern:
Upvotes: 3
Reputation: 64
Interesting so here are my findings in CMD and Git Bash if you will use just one quote whether it is a single quote or double quote the command will break and bash will intercept it as 2 different commands. This is not only in the case of git grep
but an echo
will also have the same behavior.
Here you can see that I'm using syntax similar to yours in echo
and it's not writing into the file just printing the next whole line
Now when I have added the closing quotes echo is working perfectly and writing into the file.
Now if you want to print a single quote you would have to use double quotes as starting and ending quotes and vice versa. click here for reference.
Now according to this documentation, wrapping a single quote in double-quotes works and this works in the case of grep
as well.
But its reverse (wrapping double quotes in single quotes) doesn't work in windows CMD this might be because bash is intercepting double quotes ("). But you can use git bash
and below will work properly.
Upvotes: 1