LoginSignup
32
28

More than 5 years have passed since last update.

Gitの過去コミットから検索するには

Last updated at Posted at 2017-07-29

過去コミットから検索する

チェックアウトしているブランチで

git rev-list HEAD | xargs git grep '検索文字列'

ブランチ指定

git rev-list ブランチ名 | xargs git grep '検索文字列'

全ブランチから

git rev-list --all | xargs git grep '検索文字列'

オプション指定

正規表現

git rev-list --all | xargs git grep -e '正規表現'

and,or,not条件

複数キーワードでAND,OR,NOT検索したい場合、

git rev-list --all | xargs git grep -e '検索文字列1' --and -e '検索文字列2'

これで、2つの検索文字列を同時に含む行が出力されます。
--or, --not も一緒に使えます。

前後行出力指定

検索文字列を含む前後10行を表示したい場合。

git rev-list --all | xargs git grep -10 '検索文字列'

見やすくしてみる

ファイル名を先頭に出力して、各行に行番号を出力する。

git rev-list --all | xargs git grep --heading --line-number -10 '検索文字列'
32
28
0

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
32
28