Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See if someone has any code left in the git repository

Tags:

git

This is more of a curiosity than a specific need, but my team has changed quite a bit over time. We've had to blow away some features that had been around for a while, and that got me wondering. Is there someway I could search the repo and see if there is any code left from user A.

I know I can do a git blame on particular file and see if User A has any lines in it, but is there a way I can do that on the entire repo?

Edit By "code left" I mean that User A wrote a line of code on Jan 1, 2010 and that line of code remains, unchanged, today.

Essentially, just like with git blame where it shows the user's name next to the line, but on the entire repo instead of a single file.

like image 259
taylonr Avatar asked Oct 20 '22 07:10

taylonr


2 Answers

This will print a list of all authors with the corresponding number of "owned" lines (excluding empty lines):

git ls-tree -r HEAD|cut -f 2|grep -E '\.(php|js|cc|h|cpp|hpp|c|txt|m)$' | xargs -n1 git blame --line-porcelain|grep "author "|sort|uniq -c|sort -nr

it currently matches php, js, cc, h, cpp, hpp, c, m and .txt file extensions.

Example output for the github repository UIView-Autolayout:

 747 author liamnichols
 458 author James Frost
 356 author [email protected]
 200 author Rich Turton
 124 author Richard Turton
  49 author Bart Vandendriessche
  25 author Tom Guy
  15 author David Keegan
  14 author Rich Hodgkins
  10 author Eric Horacek
  10 author Bob Spryn
   5 author Liam Nichols
   2 author Nirvana Platform
   1 author Gert Vanbeckevoort
like image 99
Daniel Avatar answered Oct 22 '22 00:10

Daniel


We use gitinspector. Which can show how many lines a user "owns" and even show what files are most owned by a given user via the -r option.

like image 21
Andrew White Avatar answered Oct 21 '22 22:10

Andrew White