Digital Defiant Studios

Published: 2013-05-21 00:00:00 -0700

Git log total LOC + refactoring

My coworker (superfamicom) showed me a fun git snippet that will allow you to see the total LOC (Lines of Code) in a given repo based on user:

  git log --author="USERNAME" --pretty=tformat: --numstat | awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -

After a few different repos, I ended up finding that most of my total linesĀ were actually negative! I was unsure how to feel about this, but I quickly realized this is a potential upside. My rationale? Negative LOC = likelihood of refactoring. This theory also jives well with my current process of development:

  1. Figure out what the problem is to solve
  2. Write some code to solve it
  3. See if it works
  4. Test(?) and commit the working code
  5. Refactor the code early and often
  6. Repeat 4-5

Just an interesting thought.