Git Search History for Specific Line of Code or String

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

If you need to track down exactly how and when a particular change happened and you are not even sure exactly where it is (perhaps because its no longer present but you are not totally sure where it was supposed to be) then this little trick can be a life saver.

You can search git log for a specific string with the -S flag

eg, searching for a constant definition


very handy indeed :)

Tags: gitdebugsearchlogstringhistory