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

Some­times you need to know when name of a vari­able or any of its default value was changed in your com­mit his­tory. The fol­low­ing com­mand will come in really handy.

git log -G<regex>

For exam­ple to search for the text — ‘wel­come’, you would use

git log -Gwelcome

This will search the con­tent of the files where the word ‘wel­come’ was present and if any changes were made to that line aka — even the word itself was not changed but its num­ber of occurences on that line changed, you would get a result.

If you are only inter­ested in know­ing when the word itself changed, use the –S option

git log -S<string>

For exam­ple

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 *