newline

TIL: searching Git logs

TIL, Git

November 29, 2020

I recently read a post about a way to search Git commit history for code, and I thought I’d summarise the post here. It’s mainly for my own reference, but others may find it useful.

The point is: git blame is very coarse-grained, searches for a single line in one file, and only reports the most recent commit. If you need more detailed results, Git has a ‘search’ feature:

To round off with an example, this is how I’d find the commit that introduced ‘expandtab’ into my dotfiles, excluding Newsboat cache, and showing the actual code:

git log --reverse -S 'expandtab' -p ':!newsboat/cache.db'