9

I looking for a way to query the git log to list the number of edited (added, updated, deleted) files where the commit message matches a specific entry. I have started with this command....

git shortlog --grep="searchtopic"

1) How do I specify the grep searchtopic to be case insensitive (grepping SEARCHTOPIC, searchtopic and Searchtopic) and 2) also apply the the Commit stats: files changed, lines added, lines deleted (total) summary ?

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
Dilemmat_Dag
  • 383
  • 1
  • 4
  • 14

1 Answers1

15

The --grep argument is handled the same way as in git log, so as with git log, use -i (also spelled --regexp-ignore-case) to ignore case.

If by "commit stats" you mean the short statistics that git log --stat prints, git shortlog does not support those at all. Since it's rather literally using (the code of) git log, it takes the --stat argument just fine, but omits the statistics.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks, I was able to improve the command `git log --grep="searchtopic" -i --oneline --shortstat`. Is it possible to summarise the stats in the end, to get total files changed, lines added/deleted? – Dilemmat_Dag Feb 06 '18 at 10:17
  • The `--stat` output is only available *per commit*; if you want a summary by user, you'd have to read all the commits selected, compute (or have Git compute) their `--stat`s, and sum them. But note that if commit X adds 1000 lines and commit Z deletes 1000 lines, they could very well be the *same* 1000 lines: do you *want* to count both sets of lines? – torek Feb 06 '18 at 15:23
  • Tracking the total amount of files changed will do, tracking lines added and deleted could not necessary in this case. – Dilemmat_Dag Feb 07 '18 at 12:41
  • I was looking for the insensitive way of doing `git grep` and `-i` works too, thanks – LasagnaAndroid Jan 07 '22 at 07:31