LoginSignup
10
8

More than 5 years have passed since last update.

":w"みたいなコロン付きのファイルをgit rmする

Last updated at Posted at 2012-07-20

Vimの操作を間違って、:wなんてファイルを作ってしまい、さらにそれをgit addしてしまいました。
こういうファイルをgitの管理外とするためには

git rm --cached '\:w'

と入力します。
で、コロンをうまくエスケープさせようしたときの試行錯誤をシミュレートすると、こんな感じになります。

$ touch :w
$ ls
:w              Rakefile        config.ru       log             vendor
Gemfile         app             db              public          webrat.log
Gemfile.lock    bin             doc             script
README.markdown config          lib             spec
$ git add .
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   :w
#
$ git rm --cached :w
fatal: pathspec 'w' did not match any files
$ git rm --cached \:w
fatal: pathspec 'w' did not match any files
$ git rm --cached ':w'
fatal: pathspec 'w' did not match any files
$ git rm --cached '\:w'
rm ':w'
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   :w
nothing added to commit but untracked files present (use "git add" to track)
$ rm :w
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
10
8
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8