git管理下で余計なファイルを消す
コードの中にあるmemcachedとかdbのnode nameなどが諸事情で変更になったので直していたのですが、 テスト以下に書かれているところの書き換えが膨大すぎるということで、ackしてsedしてしまえとおもったのでやってみました
ack -l DB_MYSQL test | xargs sed -i.bak 's/DB_MYSQL/DB_MYSQL_MASTER/g'
これでかきかわったと思ったら、bakファイルができてしまった(いらないのに)
% ls -l test total 48 -rw-r--r-- 1 nari staff 23 Nov 23 01:10 coffee_test.rb -rw-r--r-- 1 nari staff 16 Nov 23 01:06 coffee_test.rb.bak -rw-r--r-- 1 nari staff 23 Nov 23 01:10 tea_test.rb -rw-r--r-- 1 nari staff 16 Nov 23 01:06 tea_test.rb.bak -rw-r--r-- 1 nari staff 23 Nov 23 01:10 water_test.rb -rw-r--r-- 1 nari staff 16 Nov 23 01:06 water_test.rb.bak
git的にはこんな感じになる
% git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: test/coffee_test.rb # modified: test/tea_test.rb # modified: test/water_test.rb # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # test/coffee_test.rb.bak # test/tea_test.rb.bak # test/water_test.rb.bak no changes added to commit (use "git add" and/or "git commit -a")
これはちょっとうっとうしい。3つだったら消してもいいんですけど、実査は40-50くらいあっていきなりやる気がなくなったw ここは怠惰なエンジニア力を発揮すべしということで、ぐぐったらgit cleanというのが使えるらしい まずはDry Run!
% git clean -f -n test Would remove test/coffee_test.rb.bak Would remove test/tea_test.rb.bak Would remove test/water_test.rb.bak
これはいい感じなので"-n"をはずして実行!
% git clean -f test Removing test/coffee_test.rb.bak Removing test/tea_test.rb.bak Removing test/water_test.rb.bak % ls -l test total 24 -rw-r--r-- 1 nari staff 23 Nov 23 01:10 coffee_test.rb -rw-r--r-- 1 nari staff 23 Nov 23 01:10 tea_test.rb -rw-r--r-- 1 nari staff 23 Nov 23 01:10 water_test.rb
これはいい感じになった!