1

For audit purposes, I want to run a query across 100+ git repos and identify if certain author has made any commits in the last 2 months. Here is what I have so far.

for i in */.git; do ( echo $i; cd $i/..; git shortlog -sn --all --since=2.months.ago --author="First, Last"; ); done

This loops through a list of repos and gives me a number of commits made by the author. I need help to write this output to text/excel file/sheet? Also, how do I include multiple authors in the same command? Can someone guide me on how this can be achieved?

Thanks in advance!

samweb
  • 41
  • 4

1 Answers1

0

First, you can redirect the output of a command to a file:

for i in */.git; do 
  echo $i >> res; 
  cd $i/..; 
  git shortlog -sn --all --since=2.months.ago --author="First, Last"; >> res 
done

Second, do that with Git 2.38 (Q3 2022), as before that, "git shortlog -n"(man) relied on the underlying qsort() to be stable, which shouldn't have.
Fixed.

See commit df534dc (14 Jul 2022) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit dd7c820, 22 Jul 2022)

shortlog: use a stable sort

Signed-off-by: Johannes Schindelin

When sorting the output of git shortlog(man) by count, a list of authors in alphabetical order is then sorted by contribution count.
Obviously, the idea is to maintain the alphabetical order for items with identical contribution count.

At the moment, this job is performed by qsort().
As that function is not guaranteed to implement a stable sort algorithm, this can lead to inconsistent and/or surprising behavior: items with identical contribution count could lose their alphabetical sub-order.

The qsort() in MS Visual C's runtime does not implement a stable sort algorithm, and under certain circumstances, that leads to instances where two authors both are listed with 2 contributions, and are listed in inverse alphabetical order.

Let's instead use the stable sort provided by git_stable_qsort() to avoid this inconsistency.

This is a companion to 2049b8d (diffcore_rename(): use a stable sort, 2019-09-30, Git v2.24.0-rc0 -- merge listed in batch #7) (diffcore_rename(): use a stable sort, 2019-09-30), mentioned here.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250