unixorn/git-extra-commands

View on GitHub
bin/git-churn

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash
#
# https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn
#
# Written by Corey Haines
# Scriptified by Gary Bernhardt
#
# Put this anywhere on your $PATH (~/bin is recommended). Then git will see it
# and you'll be able to do `git churn`.
#
# Show churn for whole repo:
#   $ git churn
#
# Show churn for specific directories:
#   $ git churn app lib
#
# Show churn for a time range:
#   $ git churn --since='1 month ago'
#
# (These are all standard arguments to `git log`.)

set -o pipefail
set -e

git log --all -M -C --name-only --format='format:' "$@" | \
  sort | \
  grep -v '^$' | \
  uniq -c | \
  sort -rn | \
  awk 'BEGIN {print "count\tfile"} {print $1 "\t" $2}'