git grep と git blame

前に飲み会で恥ずかしい思いをしたのでメモ

git blame

git blame app/model/blog.rb

Annotates each line in the given file with information from the revision which last modified the line. Optionally, start annotating from the given revision.

指定したファイルの各行に対して、最後にその行が更新されたリビジョンを注釈としてつけてくれる。この腐ったコード書いたヤツ誰だよって言いたい時に便利。

git grep

git grep foobar

Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects.

ワークツリー中のトラックしているファイルの特定のパターンを検索する。ワークツリーとは、git add する前のもの。addするとインデックスに追加される。

いつもは "grep -r foobar *" としていたけど、ログファイルも結果に出てくるので煩わしい時があった。git grep の場合には、.gitignore で指定してあるログファイルなどは自動的に除外されるからとても便利。早いのもよし。