Slater Tyranus Slater Tyranus - 6 months ago 16
Git Question

How much of my code is still around?

Strange question, but a pretty reasonable one I think. Basically there's a project that I started several years ago with a couple hundred lines of code. Amazingly, since then it's grown to be a huge, robust project that I'm very proud of.

Now, I have a question that very often pops into my head:

How much of my code is still around?

Almost certainly the vast majority of my code has been rewritten at this point, but it feels like it should be very possible to have git give me a picture of what's still around.

Now, I've looked into this on a basic level, but can't really find anything else along these lines, though some of github's charts are helpful.

Any ideas?


So git blame is a way to go. Here is how you can calculate number of lines which was changed by each author in current revision

git ls-tree -r HEAD --name-only \
    | xargs -I{} git blame --line-porcelain {} \
    | sed -n 's/^author //p' \
    | sort \
    | uniq -c \
    | sort -rn

Which will give

15492 Alice
 3406 Bob
  100 Carol