檢查 git repo 中每個人的 commit 次數以及修改行數

雖然不應該以 commit 數跟修改行數作為判斷工程師努力程度的依據甚至績效標準,但有辦法觀察 git repo 中每個人的 commit 次數以及修改行數的話總是個不錯的輔助指標。

以下以 jQuery 的 repo 作為範例資料。

找出 repo 中每個人的 commit 次數。想要全部列出可以拿掉 head -n 10

$ git shortlog -sn | head -n 10
  1714  John Resig
   700  Timmy Willison
   587  Dave Methvin
   413  Michał Gołębiowski-Owczarek
   336  Jörn Zaefferer
   332  Julian Aubourg
   315  Rick Waldron
   278  Richard Gibson
   269  Oleg Gaidarenko
   250  Brandon Aaron

找出 git repo 中每個人的 commit 次數,但排除 merge。

$ git shortlog -sn --no-merges | head -n 10
  1601  John Resig
   687  Timmy Willison
   529  Dave Methvin
   413  Michał Gołębiowski-Owczarek
   335  Jörn Zaefferer
   312  Julian Aubourg
   303  Rick Waldron
   278  Richard Gibson
   269  Oleg Gaidarenko
   248  Brandon Aaron

找出 git repo 中每個人在指定的時間範圍內的 commit 次數,並排除 merge。

$ git shortlog -sn --no-merges --since=2010-01-01 --until=2015-01-01 | head -n 10
   520  Timmy Willison
   509  John Resig
   476  Dave Methvin
   312  Julian Aubourg
   300  Rick Waldron
   190  Oleg Gaidarenko
   182  Richard Gibson
   111  Michał Gołębiowski-Owczarek
    84  Mike Sherov
    58  Colin Snover

找出 git repo 中特定人在指定時間範圍內修改過哪些檔案,以及修改次數。-M-C 可以用來避免檔案複製/更名造成的無意義修改行數。

$ git log --author='John Resig' \
          --since=2010-01-01 \
          --until=2015-01-01 \
          --pretty=tformat: \
          --name-only \
          -M -C \
  | sort | uniq -c | sort -nr | head -n 10
  73 src/event.js
  56 src/core.js
  53 src/ajax.js
  52 version.txt
  47 src/manipulation.js
  43 src/css.js
  38 test/unit/manipulation.js
  32 test/unit/event.js
  31 src/data.js
  28 src/attributes.js

找出 git repo 中特定人在指定時間範圍內的修改行數。

$ git log --author='John Resig' \
          --since=2010-01-01 \
          --until=2015-01-01 \
          --pretty=tformat: \
          --numstat \
          -M -C \
  | awk '{add+=$1;del+=$2} END{print "Added "add" lines, deleted "del" lines"}'
Added 21957 lines, deleted 9566 lines

找出 git repo 中特定人在指定時間範圍內的修改行數,但排除特定檔案。當需要排除套件 lock 檔案(composer.lockpackage-lock.jsonPipfile.lockpoetry.lock...等等)的時候很有用。

$ git log --author='John Resig' \
          --since=2010-01-01 \
          --until=2015-01-01 \
          --pretty=tformat: \
          --numstat \
          -M -C \
  | grep -v 'version.txt' \
  | awk '{add+=$1;del+=$2} END{print "Added "add" lines, deleted "del" lines"}'
Added 21905 lines, deleted 9514 lines