You already saw in the previous recipe how we can filter the output of git log
to only list commits with the "Bug: "
string 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 "Performance"
keyword. 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 e3f19a529 Performance improvement on writing a large index 83ad74b6b SHA-1: collision detection support 48e245fc6 RefTreeDatabase: Ref database using refs/txn/committed 087b5051f Skip redundant 'OR-reuse' step in tip commit bitmap setup 9613b04d8 Merge "Performance fixes in DateRevQueue" 84afea917 Performance fixes in DateRevQueue 7cad0adc7 DHT: Remove per-process ChunkCache d9b224aeb Delete DiffPerformanceTest e7a3e590e Reuse DiffPerformanceTest support code to validate algorithms fb1c7b136 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 d7deda98d Skip ignored directories in FileTreeIterator 5a87d5040 Teach UploadPack "include-tag" in "fetch" 7d9246f16 RawParseUtils#lineMap: Simplify by using null sentinel internally 4bfc6c2ae Significantly speed up FileTreeIterator on Windows 4644d15bc GC: Replace Files methods with File alternatives d3021788d Use bitmaps for non-commit reachability checks 6b1e3c58b Run auto GC in the background db7761025 Pack refs/tags/ with refs/heads/ 30eb6423a Add GC_REST PackSource to better order DFS packs ... more output
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: