git log -G<regexp>

Searches commit diffs for changes matching a regex pattern.

This command is useful for locating commits whose diffs contain lines that match a specified regular expression, helping developers track when specific code changes were introduced.

It operates by scanning each commit’s diff output to identify modifications that add, remove, or alter lines fitting the provided pattern; this makes it invaluable when debugging issues or investigating the history of a particular code fragment.

Variations include using -S<text> to search for literal string differences instead of regex, and combining it with flags like -p, --author=<name>, or --since=<date> to further narrow down the search; additionally, commands such as git grep for repository-wide text searches or git blame to track line-by-line changes provide complementary functionality.

Related commands

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...