I create a file named ":w" with unknown reason. And I cannot delete this file using "git rm". Now I wonder how to delete this file in the branch.
3 Answers
Try to escape the filename and it should work.
git rm '\:w'
or delete the file in the filesystem and commit
rm ./?w
git commit -v -a

- 3,373
- 2
- 24
- 38
-
-
1You could also use `git rm -- :w` -- see [this](http://stackoverflow.com/q/13321458/720999). – kostix Apr 04 '14 at 14:14
From gitrevisions(7):
:, e.g. HEAD:README, :README, master:./README
A suffix
:
followed by a path names the blob or tree at the given path in the tree-ish object named by the part before the colon.:path
(with an empty part before the colon) is a special case of the syntax described next: content recorded in the index at the given path. A path starting with./
or../
is relative to the current working directory. The given path will be converted to be relative to the working tree’s root directory. This is most useful to address a blob or tree from a commit or tree that has the same tree structure as the working tree.
Therefore, the colon is treated as a special character, and not treated literally.
Try prefixing the path with ./
.
$ ls
:w
$ git rm :w
fatal: pathspec ':w' did not match any files
$ git rm ./:w
rm ':w'

- 897
- 6
- 13