官术网_书友最值得收藏!

Finding commits in history

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.

Getting ready

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.

How to do it...

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 

How it works...

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
...

There's more...

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:

主站蜘蛛池模板: 麻栗坡县| 饶河县| 南开区| 新巴尔虎右旗| 龙泉市| 台江县| 建平县| 南京市| 莆田市| 尤溪县| 磴口县| 郧西县| 广德县| 清流县| 神池县| 孟连| 砚山县| 安阳县| 铁岭县| 会东县| 竹山县| 正镶白旗| 大连市| 合川市| 宝应县| 伽师县| 象州县| 杭锦后旗| 浪卡子县| 郧西县| 灵宝市| 图木舒克市| 防城港市| 通化县| 连州市| 永德县| 汾西县| 霍山县| 博爱县| 尼勒克县| 金华市|