search Git history, ignoring certain directory
11 Apr 2016
Ever wanted to look through a Git repository’s history for a commits involving a specific string, but ignoring a certain directory (e.g. for packaged/built code)?
As of Git 1.9, you’re in luck! In the file listing, you can now exclude certain paths by starting them with
:! but your shell might mess with that):
git log -u -S fooBar -- . ":(exclude)public/pkg/" ":(exclude)vendor/"
This will look through the current directory (
., with the
-- indicating the end of the options and the beginning of the paths) for commits which add or remove the string “fooBar”, but will not look through the
vendor/ subdirectories of the current directory.
Tip of the hat to VonC on StackOverflow.