Last Updated: February 25, 2016
· nvie

Search your git commits and auto-show matches

Looking for a specific piece of code in your git commit history?

The following alias searches through all git commits for diffs containing the specified search string and opens them one-by-one in a pager:

git-search () {
    git log --all -S"$@" --pretty=format:%H | map git show 

It starts with the first matching commit (the most recent match). To open the next match, simply close the pager with q. To abort, just use Ctrl+C.

This uses the map function, defined in a previous protip.