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
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.
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.
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.
found the answer not 5 minutes later
git rm '\:w'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With