1

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.

umläute
  • 28,885
  • 9
  • 68
  • 122
Ryan Kohn
  • 13,079
  • 14
  • 56
  • 81

1 Answers1

5

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):

git add -p \(External\)/Project/Filename.cs

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.

git add -p \(E[tab]...

if this doesn't help, you could simply try to first cd into "(External)/Project" and then use

git add -p Filename.cs

UPDATE

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 to git add -p and which seems to work, even with parentheses.

umläute
  • 28,885
  • 9
  • 68
  • 122
  • @toby-allen thanks; i'm having troubles with my inline editor :-) – umläute Jan 16 '13 at 15:35
  • It's possibly relevant that I'm on Windows. FYI: I also tried `cd` into the sub-directory, but I get the exact same error message. – Ryan Kohn Jan 16 '13 at 15:35
  • yes, i think this is relevant; which shell are you using? `cmd` or the "git-shell" that comes with git (and is afair a mingw-bash or some cygwin-shell) – umläute Jan 16 '13 at 15:48
  • I'm using msysgit, which uses MINGW32. I get the same results using `cmd` though. – Ryan Kohn Jan 16 '13 at 15:55