I want to run git add -p on a file with a full path that includes parentheses, like so:
git add -p "(External)/Project/Filename.cs"
However, when I run this, I get the following error:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `git ls-files -- (External)/Project/Filename.cs'
I have also tried escaping the parentheses using \, but I get the same error. For comparison, a regular git add has no issues with the parentheses.
How can I pass in this file to git add -p?
EDIT: It seems relevant that I’m using Windows.
You are most likely having a problem with your shell wrongly escaping your parenthesis.
Using the following, worked for me (no need for quotes, only escaping the parenthesis with backslash):
in order to do the escaping right, I find it very helpful to use the auto-completion capabilities of bash, something like the following helps constructing the filename in a “bash-safe” way.
if this doesn’t help, you could simply try to first
cdinto “(External)/Project” and then useUPDATE
if you are using W32 (which is obviously the case), then i can confirm the problem.
the only workaround i found so far is to use
git gui, which is simply a nice front-end togit add -pand which seems to work, even with parentheses.