How to search indexed content?

git grep -n keyword

To search the contents of tracked files use git grep -n keyword. Add -n parameter to show the line numbers of the matching lines.

Layer 1
Terminal Example
git grep -n post
app/controllers/blog_controller.rb:3:    @blog_posts = blog_posts
app/controllers/blog_controller.rb:7:    @blog_post = blog_posts.find { |p| p["slug"] == params[:id] }
app/controllers/blog_controller.rb:8:    render @blog_post["slug"].underscore, layout: 'blog_post'
app/controllers/blog_controller.rb:12:   def blog_posts
app/controllers/blog_controller.rb:13:   @blog_posts ||= YAML.load_file("config/blog_posts.yml")
app/javascript/packs/application.js:148: type: 'post',
app/views/blog/index.html.erb:5:         <% @blog_posts.each do |blog_post| %>
app/views/blog/index.html.erb:8:         <%= blog_post["title"] %>
app/views/blog/index.html.erb:9:         <%= blog_post["excerpt"] %>

See git grep to learn more about it.

Last modified on November 30, 2021.

You might also like