1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

git grep がかなり便利

Posted at

git grep がかなり便利

普段開発をしている中で、特定の単語でファイル内を手軽に検索したい場合がある。
もちろんソースコードをvscodeで開いて検索しても良いが、一工程加わるので、面倒な時がある。そんなときに git 管理しているものであれば、git grep コマンドが使える。
感覚的には Linux の locate コマンドに近い。

How to use?

 $ git grep "検索したい文字列"

のような感じで使える。

例えば、以下を実行すると、

 $ git grep 'def current_user'

下のような結果が得られる。

app/lib/inline_renderer.rb:  def current_user
app/policies/application_policy.rb:  def current_user
app/serializers/rest/announcement_serializer.rb:  def current_user?
app/serializers/rest/poll_serializer.rb:  def current_user?
app/serializers/rest/reaction_serializer.rb:  def current_user?
app/serializers/rest/status_serializer.rb:  def current_user?
app/serializers/rest/tag_serializer.rb:  def current_user?

ちなみに上は、mastodon の repository を fork & clone してローカルで試した結果。

参考: https://github.com/mastodon/mastodon

他の使い方

公式ドキュメントには様々なオプションが載っている。
色々やってみると面白いかもしれない。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?