3

I have a weird case - My git was working fine till an hour ago or so but now when I try to run

git add * --all

I get an error saying error: unknown switch `C'.

Below is the output I got. I just pulled from the repo which had some changes and after that I started getting this error. Tried poking around a bit and found that the error comes because of the * sign. If I remove that, it works....

$ git add * --all
error: unknown switch `C'

usage: git add [options] [--] <pathspec>...

-n, --dry-run         dry run
-v, --verbose         be verbose

-i, --interactive     interactive picking
-p, --patch           select hunks interactively
-e, --edit            edit current diff and apply
-f, --force           allow adding otherwise ignored files
-u, --update          update tracked files
-N, --intent-to-add   record only the fact that the path will be added later

-A, --all             add changes from all tracked and untracked files
--ignore-removal      ignore paths removed in the working tree (same as --no-all)
--refresh             don't add, only refresh the index
--ignore-errors       just skip files which cannot be added because of errors
--ignore-missing      check if - even missing - files are ignored in dry run
Mureinik
  • 297,002
  • 52
  • 306
  • 350
Kshitiz
  • 2,852
  • 5
  • 32
  • 41
  • 4
    You have a file named `-C`, so `add *` turns into `add -C file1 file2...`. – torek Oct 01 '14 at 15:31
  • Thank @torek, found the file and deleted it. If any one else is looking for something similar, delete the file using rm -- -c [-- prevents the command from parsing the parameters] – Kshitiz Oct 02 '14 at 07:35

4 Answers4

5

You should not have options (like --all) like after parameters (like filenames). So try switching them around:

git add --all *

Additionally, if a filename begins with a minus it will be mis-interpreted as an option (a file -Clown looks like options -C -l -o -w -n to programs on the commandline). To mitigate this you can stop option parsing using --:

git add --all -- *
Nils Werner
  • 34,832
  • 7
  • 76
  • 98
  • While you are correct, as Mureinik noted the combination of `--all` and `*` doesn't make sense. Maybe you want to mention that. – Sascha Wolf Oct 02 '14 at 10:50
1

switches should come before the file list - I'm guessing you have a file named C which the * is expanded to by the shell. Note, however, that with --all you do not need to provide a file list:

git add --all
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

You might be running in a Powershell console. (that was my case)

(If you want to keep the output in the same console window you can just start an "ordinary" command in your console through cmd. (it will have its own history though) You then leave it by exit.)

LosManos
  • 7,195
  • 6
  • 56
  • 107
-1

If you're using Windows, its probably because you're using Visual Studio's command prompt, or some other special Windows command utility. Use the basic Command Prompt, or use Git Bash (which is what I did). The command I was trying was:

git merge --squash HEAD@{1}

After trying it in a git-bash window, it worked.

  • your answer has nothing to do with the problem. please consider removing it and ask yourself have I provided a solution that applies directly to the question asked and would resolve it? The OP's question had an issue in his command that would be wrong on any console. Your answer is ostensibly to a different question entirely. – UpAndAdam Jul 19 '23 at 18:21