概要
rmしても消せないファイル("\r"みたいなやつ)をたまに作っちゃう(1ヶ月に一回くらいある...)
ので消す方法メモ
手順
調べるのが面倒なので、こんな邪道になりました。
- 対象のディレクトリをgit管理下に置くする
- 消したいファイル以外を退避しておく
- 消したいファイルをstashする
- 消したいファイルを
git stash dropする git 管理下にあるファイルを削除する方法
詳細なコマンド
git statusすると下記のようなファイルがあるとする
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: sample.rb
Untracked files:
(use "git add <file>..." to include in what will be committed)
"\r"
↑の"\r"を消したいです
関係ないファイルを退避する
とりあえずcommitしておいて、あとでgit reset --mixed @^でもとに戻すことにします
git add sample.rb git commit -m "WIP"
stashしてdropする
git stash --keep-index --include-untracked git stash drop 0
完了
必要に応じてgit reset --mixed @^する
正規の方法で消す方法知ってたらどなたかコメントください...