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`
If the string exists in your repo, anywhere, you'll get something like this:
***c5cd1d8:path/to/file.js:let a = "the magic string"
Once you have that data, it's as easy as finding the branch!
git branch --contains ***c5cd1d8
There may be an easier way to do this. What do you recommend?
Top comments (7)
You might want to check out the options on the
git log
command as well, as it can be used to search across all history rather than just all current branches. For example to search all commit messages for the string "foo bar baz":If you want to search file contents, you can use the "pickaxe". Not sure how you do multiple words, but for the single word "foo":
This will search all commits for the word "foo" being added or removed.
Awesome! Thank you!
Hi! Great post! I was in need of the same thing. One question, though. Does this search across all branches but also across all commits inside each branch (=the whole repo, at each of the stages)? Thanks.
Nice, just what I needed.
Thanks.
So why wouldn't you simply pull that branch locally and search for the string using your IDE / Editor?
I want sure what branch the change was in.
great