Search in git history

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the git category.

Last Updated: 2024-04-23

You can search git history for any piece of code matching a regex by using the -G flag

# Any line of code matching 7.7.X
git log -G "7.7.\d"

To search for plain text

git log -S "console.log"

To search search just the commit messages

git log --grep="Merge pull request"

Very often you'll want reversed output

git log -G "7.7.\d" --reversed

Or to limit times

git log -G "7.7.\d" --since="1 week ago"