2

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.

Jun HU
  • 3,176
  • 6
  • 18
  • 21

3 Answers3

4

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
Simson
  • 3,373
  • 2
  • 24
  • 38
1

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'
Alex Trebek
  • 897
  • 6
  • 13
0

I just tested it and if you do

$ git rm ./:w

It will work

user3361136
  • 63
  • 1
  • 3