Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Git Version Control Cookbook

You're reading from   Git Version Control Cookbook 90 hands-on recipes that will increase your productivity when using Git as a version control system

Arrow left icon
Product type Paperback
Published in Jul 2014
Publisher
ISBN-13 9781782168454
Length 340 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (14) Chapters Close

Preface 1. Navigating Git FREE CHAPTER 2. Configuration 3. Branching, Merging, and Options 4. Rebase Regularly and Interactively, and Other Use Cases 5. Storing Additional Information in Your Repository 6. Extracting Data from the Repository 7. Enhancing Your Daily Work with Git Hooks, Aliases, and Scripts 8. Recovering from Mistakes 9. Repository Maintenance 10. Patching and Offline Sharing 11. Git Plumbing and Attributes 12. Tips and Tricks Index

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:

There's more...
You have been reading a chapter from
Git Version Control Cookbook
Published in: Jul 2014
Publisher:
ISBN-13: 9781782168454
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image