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
  • 62,560
  • 7
  • 92
  • 110
chrisheyn
  • 774
  • 5
  • 18
  • 1
    Could you show us a sample of the expected output given an input? Not exactly sure what you mean by 'sum of commits in this list' – Inian Apr 22 '18 at 10:16
  • Hi @Inian. I just want to get the number of commits that matches the given string in commit message. – chrisheyn Apr 22 '18 at 10:18
  • Doesn't `git log --all --grep='SEARCH_STRING' --count` work? or even `git log --all --grep='SEARCH_STRING' | wc -l` ? – Inian Apr 22 '18 at 10:22
  • the first one gives just the list again. The second counts the numbers of lines in this list. – chrisheyn Apr 22 '18 at 10:25

1 Answers1

2

I think I found it

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

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

chrisheyn
  • 774
  • 5
  • 18
  • 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