gitで1ファイルを過去のコミットへ戻す

gitでうっかりファイルを上書きしてコミット、昔の変更が飛んでしまった..ときの修正ファイルの戻し方

git logとかtigとかgithubとかbitbucketとかお使いのもので、ハッシュを調べます

$ git log /path/to/file
とかで 791d6ce を調べて

$ glt checkout 791d6ce /path/to/file

これでstagingに戻ります
(git add された状態)

gitでaddしてないファイルをすべてなかったことにする

gitで管理してるディレクトリに大量にファイルをしてしまった..

$ git status

On branch v.2.13.3
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:   data/Smarty/templates/default/abouts/index.tpl
        modified:   data/Smarty/templates/default/cart/index.tpl
        modified:   data/Smarty/templates/default/contact/complete.tpl
        modified:   data/Smarty/templates/default/contact/confirm.tpl
        modified:   data/Smarty/templates/default/contact/index.tpl
        modified:   data/Smarty/templates/default/entry/complete.tpl
        modified:   data/Smarty/templates/default/entry/confirm.tpl
        modified:   data/Smarty/templates/default/entry/index.tpl
        modified:   data/Smarty/templates/default/entry/kiyaku.tpl
        modified:   data/Smarty/templates/default/error.tpl
        modified:   data/Smarty/templates/default/footer.tpl
        # 延々に続く..

となったときに全て無かったことにするには

$ git clean -f

これで元通り
あ、すべて消えるのでご使用はお気をつけてください

CakephpのbeforeFilterでComponentを使うときのエラー

CakephpのbeforeFilterでComponentを使っているとなんやらメソッドがないとかエラーが

Fatal error: Call to a member function save() on a non-object ...

えー、普通に使ってるのに..と思ったら、beforeFilterでは、Componentのstartupがまだ呼ばれてないっぽい(使える準備ができてない)
仕方ないので、メインのメソッドに書きました