You already saw in the previous recipe how we can filter the output of
git log to only list commits with the string
"Bug: " in the commit message. In this example, we will use the same technique to find specific commits in the entire history.
Again, we will use the JGit repository, trying to find commits related to the keyword
"Performance". In this recipe, we will look through the entire history, so we don't need the master branch to point to a specific commit.
As we tried earlier, we can use the
--grep option to find specific strings in commit messages. In this recipe, we look at the entire history and search every commit that has
"Performance" in its commit message:
$ git log --grep "Performance" --oneline --all 9613b04 Merge "Performance fixes in DateRevQueue" 84afea9 Performance fixes in DateRevQueue 7cad0ad DHT: Remove per-process ChunkCache d9b224a Delete DiffPerformanceTest e7a3e59 Reuse DiffPerformanceTest support code to validate algorithms fb1c7b1 Wait for JIT optimization before measuring diff performance
In this example, we specifically ask Git to consider all of the commits in the history, by supplying the
--all switch. Git runs through the DAG and checks whether the
"Performance" string is included in the commit message. For an easy overview of the results, the
--oneline switch is also used to limit the output to just the subject of the commit message. Hopefully then the commit(s) we needed to find can be identified from this much shorter list of commits.
Note that the search is case sensitive; had we searched for
"performance" (all in lower case), the list of commits would have been very different:
$ git log --grep "performance" --oneline --all 5ef6d69 Use the new FS.exists method in commonly occuring places 2be6927 Always allocate the PackOutputStream copyBuffer 437be8d Simplify UploadPack by parsing wants separately from haves e6883df Enable writing bitmaps during GC by default. 374406a Merge "Fix RefUpdate performance for existing Refs" f1dea3e Fix RefUpdate performance for existing Refs 84afea9 Performance fixes in DateRevQueue 8a9074f Implement core.checkstat = minimal 130ad4e Delete storage.dht package d4fed9c Refactored method to find branches from which a commit is reachable ...
We also could have used the find feature in Gitk to find the same commits. Open Gitk with the
--all switch, type
Performance in the Find field and hit Enter. This will highlight the commits in the history view and you can navigate to the previous/next result by pressing Shift + up arrow, Shift + down arrow, or the buttons next to the Find field. You will still, however, be able to see the entire history in the view with the matching commits highlighted: