Frage

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.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top