Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
Created February 16, 2011 19:04
Show Gist options
  • Select an option

  • Save coreyhaines/829932 to your computer and use it in GitHub Desktop.

Select an option

Save coreyhaines/829932 to your computer and use it in GitHub Desktop.
Bash script to generate churn counts in git repo
churn number and file name
git log --all -M -C --name-only | grep -E '^(app|lib)/' | sort | uniq -c | sort | awk 'BEGIN {print "count,file"} {print $1 "," $2}'
churn number and file name w/ limiting to last n commits
git log --all -n 5000 -M -C --name-only | grep -E '^spec/models' | sort | uniq -c | sort | awk 'BEGIN {print "count,file"} {print $1 "," $2}'
graph of churn number and frequency
git log --all -M -C --name-only | grep -E '^(app|lib)/' | sort | uniq -c | sort | awk '{print $1}' | uniq -c | sort | awk 'BEGIN { print "frequency,churn_count"} { print $1,$2}'
@coreyhaines

Copy link
Copy Markdown
Author

Gary,

I think the graphs over time would be more of an interest from an archeological perspective, rather than changing my current habits.

Thanks for the tip on passing $* to it. I'll do that when I build a script. Or, I could just make a function to put in my bash_profile, no? Maybe I'll ping you to help me.

@garybernhardt

Copy link
Copy Markdown

Yeah, it'd be fine as a function. A script makes it slightly more reusable for others since they just drop the file any where on their $PATH.

@coreyhaines

Copy link
Copy Markdown
Author

True about making it more reusable. I could put it into my dotfiles repo.

@coreyhaines

Copy link
Copy Markdown
Author

Or, you could, and I can just copy it. HAHA!

@garybernhardt

Copy link
Copy Markdown

Done. https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn

I removed your grep for 'app|lib'. You can just pass directories straight to git log to log them. This script should work exactly like yours did.

@coreyhaines

Copy link
Copy Markdown
Author

Awesome, Gary! Thanks!

@danmayer

Copy link
Copy Markdown

This might need some more work, haven't done anything with it for awhile, but this tracks files, classes, and methods for a ruby project

https://github.com/danmayer/churn

@huebnerdaniel

Copy link
Copy Markdown

Great, this helped me a lot. Thanks!

@Xodarap

Xodarap commented Mar 9, 2017

Copy link
Copy Markdown

If you add -n to the final sort it will sort numerically instead of alphabetically

@fuhrmanator

Copy link
Copy Markdown

If you remove -all it allows specifying an SHA1 in the log as churn up to that SHA1.

@fuhrmanator

Copy link
Copy Markdown

I just found https://github.com/AnAppAMonth/git-churn, which is a python solution giving a more detailed interpretation of churn (additions, subtractions).

@flacle

flacle commented Nov 2, 2020

Copy link
Copy Markdown

Solutions that I've found online looked at changes to files irrespective whether these are new changes or edits to existing lines of code. Hence I made this solution: https://github.com/flacle/truegitcodechurn/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment