includeJS
  • courses
  • egghead
  • git

Analyze Git Logs with the Command Line

Stuff I learned from the Egghead course Analyze Git Logs with the Command Line

Question: how to figure out which of your days were the most productive (on which days you made the highest number of commits?). This example uses my team's commits for 2019 front-end application written in ReactJS.

  1. git log | grep 2019

Get commits from 2019 (pipe the log through a filter).

  1. git log | grep 2019 | wc -l

Count how many commits were made in 2019 (count the number of lines).

  1. git log | grep 2019 | sed -e 's/Date: //' | sed -e 's/\(...\).*/\1/'

To get out the days when the commits were commited (using sed and regex magic).

  1. git log | grep 2019 | cut -d ' ' -f 4

Same as above (cut into groups using the delimiter - empty space in this case).

  1. git log | grep 2019 | tr -s ' '

Squeezes the output (removes the extra spaces in this case).

  1. git log | grep 2019 | tr -s ' ' | cut -d ' ' -f 2

Combines the translate and cut commands to get the same output as number 3. (regex madness from above).

  1. git log | grep 2019 | awk '{ print $2 }'

Same result as above, but using awk.

  1. git log | grep 2019 | awk '{ print $2 }' | sort | uniq -c

Count the number of occurences of each day (make sure to run sort before uniq, as uniq only removes neighboring duplicates).

  1. git log | grep 2019 | awk '{ print $2 }' | sort | uniq -c | sort -n

Sort the final result and add -n for when sorting numbers.

Final result: (Who would have thunk it, Mondays are the least productive of all weekdays 🤔).

numberday
16Sun
18Sat
278Mon
316Fri
323Wed
351Thu
359Tue

(hey, my first table in markdown 💪!)