Archonic
Archonic

Reputation: 5362

How to git rm a file whose name starts with ':'

I've accidentally got a file in my repo named :web,. When typing git rm :web, it seems to think the colon is a part of a command and not the start of a filename:

fatal: pathspec 'web,' did not match any files

Quotes don't make a difference.

Upvotes: 3

Views: 736

Answers (2)

Keith Thompson
Keith Thompson

Reputation: 263217

Yet another alternative:

git rm ./:web

Prepending ./ to a name that refers to a file in the current directory makes it refer to the same file, but it doesn't have : as the first character. (This also works for file names starting with -.)

Note that this assumes that git rm only treats the : character specially if it occurs at the beginning of the file name. I think that's the case, but I haven't personally confirmed it.

Upvotes: 2

Carl Norum
Carl Norum

Reputation: 224864

You need to escape the : (and not just in your shell, but for git itself):

git rm '\:web,'

or

git rm \\:web,

Alternatively, you could use the :-based pathspec that the error is telling you about. For example:

git rm :::web,

Upvotes: 5

Related Questions