Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git remove file starting with a colon

I accidentally created a file named :w. I managed to delete it by using zsh tab feature. But I cannot remove it from my git cache.

    git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   Gemfile
#   modified:   Gemfile.lock
#   new file:   config/newrelic.yml
#
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    :w
#

then

git rm :w
fatal: pathspec 'w' did not match any files
like image 892
Harry Moreno Avatar asked Sep 27 '13 19:09

Harry Moreno


People also ask

How do I remove a file from a git command?

The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory.

How do I delete a file name?

Alternatively, head to the folder containing the files you want to delete, hit Shift + Right Click, and select Open a command window here. Then input "del [filename]" and press Enter.

How do I delete a file from the start in Linux?

You can use standard UNIX or Linux rm command to delete a file name starting with - or -- . All you have to do is instruct the rm command not to follow end of command line flags by passing double dash -- option before -foo file name.


1 Answers

found the answer not 5 minutes later

git rm '\:w'
like image 154
Harry Moreno Avatar answered Sep 29 '22 15:09

Harry Moreno