How to search for changes to some text in the commit history

Sometimes you need to know when name of a variable or any of its default value was changed in your commit history. The following command will come in really handy.

git log -G<regex>

For example to search for the text – ‘welcome’, you would use

git log -Gwelcome

This will search the content of the files where the word ‘welcome’ was present and if any changes were made to that line aka – even the word itself was not changed but its number of occurences on that line changed, you would get a result.

If you are only interested in knowing when the word itself changed, use the -S option

git log -S<string>

For example

git log -Swelcome

Note that -G accepts a regex whereas -S accepts a string.


Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *