LoginSignup
4

More than 5 years have passed since last update.

`git clean -f`を知らなくて全く意味のないコマンドを書いた思い出

Last updated at Posted at 2017-05-09

よくわからないけど、以下のような状態になりました。全部消したいです。

$ git status
On branch master
Your branch is up-to-date with 'upstream/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

     (copy: conflict on 2017-05-09).gitignore
    app/assets/javascripts/front/solutions.js (copy: conflict on 2017-05-09).coffee
    app/assets/stylesheets/front/detailmain (copy: conflict on 2017-05-09).scss
    app/assets/stylesheets/front/theme (copy: conflict on 2017-05-09).scss
    app/controllers/mypage/profiles_controller (copy: conflict on 2017-05-09).rb
    app/controllers/user/mail_activate_controller (copy: conflict on 2017-05-09).rb
    app/models/user (copy: conflict on 2017-05-09).rb
    app/views/console/solutions/_form.html (copy: conflict on 2017-05-09).slim
    app/views/pages/index.html (copy: conflict on 2017-05-09).slim
    config/initializers/paperclip (copy: conflict on 2017-05-09).rb
    db/schema (copy: conflict on 2017-05-09).rb
    spec/requests/console/solutions_spec (copy: conflict on 2017-05-09).rb

nothing added to commit but untracked files present (use "git add" to track)
$ git clean -f

を使えば良いのですが、それを知らないぼくは、ただただ意味のないコマンド を書きました。

$ git status -s | cut -c4- | sed -e 's/\([ |\(|\)]\)/\\\1/g' | xargs rm -fr

勉強になりました。ありがとうございました。

追記

Untracked なファイルを消すには、git clean -f で良いのですが、ディレクトリだとこのコマンドは削除してくれなかったです。なので、たくさんいらないディレクトリとか、ファイルとかがあるときは、上の思い出コマンドも使えるかもしれないと思いました。(そんな機会は訪れないと思いますが...

追記2

git clean -df でディレクトリも消せました。めでたしめでたし。

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
4