Find A String in a Massive Git Repo

Doug Black - May 8 '19 - - Dev Community

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?

. . . . . . . .
Terabox Video Player