I’m trying to search for changes in my git history relating to a very specific variable name.
I’ve tried doing this:
git diff HEAD~25000 | grep -in mydistinctvariablename
The results don’t tell me which commit the result lines are from and it takes quite a bit of time (about 5-7 minutes).
Does anyone have a better solution, time and results wise?
git log is generally the command to use when examining commit history.
git log --grepcan be used to search for regular expressions in the commit message.What you are after is
git log -Swhich searches the commit content simply orgit log -Gwhich searches it with a regular expression:So, for instance, in the
msysGitrepository I can find the commit that introduced Tcl 8.5.8 using either:which just looked for 8.5.8 in the commit messages or as you want to do looking at a string that only occurred in the committed diff:
The range limiting you have in your sample can still be used here to limit the commits to be examined. Read though the git log manual carefully to get a good idea of all the things it can do.
Note that
-Sjust looks for simple string differences – if you really want to search the content using a regular expression similar to you example then you should use the-Goption instead of-Sbut this will be significantly slower.