How can I search my ENTIRE git repo's commit history for a string change?
Asked Answered
A

1

7

I have a website/repo.

Part of my website says:

"Powered by https://myotherwebsite.com/'"

at some point, some troll I had working on the website switched it to say:

"Powered by https://theirwebsite.com"

How can I search the entire repo history to the commit where this change was made.

There have been A LOT of commits/branches over the years.

Advent answered 7/2, 2019 at 6:33 Comment(0)
H
10

If you can ignore dead branches and assume that all relevant code is reachable from your most recent master version, I'd recommend using the -S option of git log :

git log -S "theirwebsite"

Take a look at the doc, and maybe consider using regexp search if your actual need is or becomes more complex than what you described here.


Even better : with --all you can search your entire repo (thanks to j6t for the trick!)

git log --all -S "theirwebsite"

(and, as noted by vfalcao, consider using the --name-only option here to list files where this change happened.)

Hans answered 7/2, 2019 at 6:44 Comment(3)
The restriction to ignore dead branches is not necessary. Just add --all to the suggested git log command to search all branches.Flail
consider using git log --all --name-only -S "theirwebsite", which is going to list the files changed in each commit as well. It can help you to narrow down the exact changing point.Ciel
@Ciel Thanks, I had failed to notice your comment at the time!Hans

© 2022 - 2024 — McMap. All rights reserved.