Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Quick Tip: Grep in Git

DZone's Guide to

Quick Tip: Grep in Git

Learn about two features in Git that will make your life way easier by simplifying searching: git-grep and git-log grep.

· DevOps Zone ·
Free Resource

Read why times series is the fastest growing database category.

This quick tip is about two small features of Git I wish I had known about earlier as it makes it way easier to do searching through it.

git-grep

git-grep is a way to search through your tracked files for whatever you provide. For example, if we want all files with the word index in it: git grep index

Demo of git grep

We can limit to specific files, for example, if we want to filter the above example to just JSON files: git grep index -- '*.json'Demo of git grep with filter

We can search for multiple items in a single file, for example, if we want to find all files with index and model in it: git grep --all-match -e index -e modelDemo of git grep with multiple filters

git-log grep

git-log has a grep function too which is awesome for finding commit messages with a specific word or words in it. For example, if I want to find all commits about Speakers for DevConf I could do: git log --all --grep "Speaker"

Git log grep example

Learn how to get 20x more performance than Elastic by moving to a Time Series database.

Topics:
devops ,git ,grep ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}