1

I have added and committed a file ----MY_Session.php. I left hyphens in the beginning by mistake. Now I want to delete this file, but when I try to run

git rm -----MY_Session.php

it throws the following error.

error: unknown option `---MY_Session.php'
usage: git rm [options] [--] <file>...

-n, --dry-run         dry run
-q, --quiet           do not list removed files
--cached              only remove from the index
-f, --force           override the up-to-date check
-r                    allow recursive removal
--ignore-unmatch      exit with a zero status even if nothing matched

I tried all the options listed above but none of them worked.

How can I delete this file?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Zeshan
  • 2,496
  • 3
  • 21
  • 26
  • Try using the `--` symbol. See http://stackoverflow.com/questions/5711356/delete-a-branch-starting-with-a-hyphen – saricden Mar 22 '15 at 09:13

2 Answers2

3

Try

git rm -- ----MY_Session.php

The '--' should stop the parsing of command line options and consider ----MY_Session.php as the filename.

NDY
  • 3,527
  • 4
  • 48
  • 63
1

You can use a glob pattern in your git rm call to remove your file without specifying the dashes:

git rm '*MY_Session.php'

Of course, you would want to make sure that this pattern won't match any other files besides ----MY_Session.php.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • *Of course, you would want to make sure that this pattern won't match any other files besides `----MY_Session.php`.* For more robustness, you could use `?` instead of `*`, as in `git rm '?---MY_Session.php'`. – jub0bs Mar 22 '15 at 09:59