Skip to content

Instantly share code, notes, and snippets.

@mscottford
Last active March 26, 2021 15:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mscottford/4e030fcc7d88deadf50659056660ae8e to your computer and use it in GitHub Desktop.
Save mscottford/4e030fcc7d88deadf50659056660ae8e to your computer and use it in GitHub Desktop.
Git Churn command

Instructions for running on Windows 10 (via Ubuntu Bash)

  1. Open Ubuntu bash environment shell
  2. Install dependencies
    sudo apt-get update
    sudo apt-get install git curl
    
  3. Create bin directory in your home folder
    mkdir -p ~/bin
    
  4. Download git-churn script into ~/bin
    curl -o ~/bin/git-churn https://gist.githubusercontent.com/mscottford/4e030fcc7d88deadf50659056660ae8e/raw/76719af714c06f39a940478ac0345484271d42f1/git-churn
    
  5. Mark the churn script as executable
    chmod 775 ~/bin/git-churn
    
  6. Switch to a cloned copy of the repository
    git churn > lifetime-churn.txt
    git churn --since='3 months ago' > recent-churn.txt
    
# Scriptified by Gary Bernhardt
# Slightly modified by M. Scott Ford
#
# 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`.)
#
# you might move this to `~/bin`, mark as executable, and then you'll be able to run it with
# `git churn`
set -e
git log --all --find-renames --find-copies --name-only --format='format:' "$@" | sort | grep -v '^$' | uniq -c | sort -n | awk 'BEGIN {print "count\tfile"} {print $1 "\t" $2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment