Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With git, how do you search for a file pattern with `git log` instead of a file path?

You can limit your git log search to a file like so:

git log [branch] -- foo.c

But how would you limit the search to a file pattern instead of a full path?

  • Consider that you may run git log on another branch, where shell expansion of * won't work, so you can't depend on the shell to do the file pattern matching.
  • Also, you can't specify a branch with git ls-files.
like image 694
Neil Avatar asked Jan 21 '11 17:01

Neil


2 Answers

Or just drop the leading ., i.e.:git log -- *foo.c, or even git log -- ./*foo.c

like image 161
Jason Lewis Avatar answered Sep 21 '22 07:09

Jason Lewis


I tend to do things like this:

git ls-files [--with-tree=<branch>] [path] | grep '<pattern>' | xargs git log [branch]
like image 39
Cascabel Avatar answered Sep 19 '22 07:09

Cascabel