git

Find A String in a Massive Git Repo

dougblackjr

Doug Black

Posted on May 8, 2019

Find A String in a Massive Git Repo

Figure I would share this, as I just needed to do this.

We have a massive git repo for an Engauge Analytics project we are working on. Tons of these branches have active work being done, and some were just skipped during the pruning process.

I needed to find 10 characters.

Technically, I needed to find the method that contained those 10 characters, but I knew those 10 characters would be the key to finding it.

Let's say you're looking for a string title the magic string in one of your many git branches in your repo. You can use:

git grep "the magic string" `git show-ref --heads`
Enter fullscreen mode Exit fullscreen mode

If the string exists in your repo, anywhere, you'll get something like this:

***c5cd1d8:path/to/file.js:let a = "the magic string"
Enter fullscreen mode Exit fullscreen mode

Once you have that data, it's as easy as finding the branch!

git branch --contains ***c5cd1d8
Enter fullscreen mode Exit fullscreen mode

There may be an easier way to do this. What do you recommend?

💖 💪 🙅 🚩
dougblackjr
Doug Black

Posted on May 8, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related