3

Is it possible to get a number of git commits filtered by commit-message?

$ git log --all --grep='SEARCH_STRING'  

With this snippet I get a list of all commits with the searched string. But I got a lot of commits and its hard to count this by Hand.

Is there a way git tells me the sum of the commits in this list?

Inian
  • 80,270
  • 14
  • 142
  • 161

1 Answers1

2

I think I found it

$ git rev-list --all --grep='SEARCH_STRING' --count

Thanks to @Inian for the tip with --count.

  • 2
    That's the right answer (well, one of several possible ones, but the one I would use). In general, if you have a `git log` command that you want to turn into some sort of scripting thing, you just replace `log` with `rev-list`. They mostly have the same options from that point forward, but `log` shows commits to a user, while `rev-list` simply lists their hash IDs. Adding `--count` replaces the list of hash IDs with counts of hash IDs (usually one count, but see `--left-right` and symmetric difference; this gets you two counts). – torek Apr 22 '18 at 16:43
  • 1
    Cool comment learned a lot from it as always, like any other post or comment by torek – CodeWizard Apr 22 '18 at 21:16