Jason
Jason

Reputation: 534

How to see all lines of code I've added to a codebase?

I want to see all the lines of code that I've added to a codebase because I want to run a character frequency count. I'd like something like git show for each commit I've authored, but I need the command to only show the lines of code added, not the lines of code removed or the overview info that git show shows at the top.

(I'm not married to git show, maybe there's a better command, it's just the closest command I know.)

My best solution is to use git log --author=<me> and only get the commit shas (there's a command for this, I don't know it offhand). Then I can loop over the shas and do git show -p <sha>, but that gets me things I don't want (lines removed, and the overview). Any help is appreciated.

Upvotes: 0

Views: 95

Answers (2)

mmlr
mmlr

Reputation: 2155

You can use git log -p directly to get the patch inline with the log. Reducing the commit message with the --oneline option makes it easy to strip out. Then simply filter for the + lines of the patches, first filtering out the +++ of the diff header and finally strip the leading +:

git log -p --oneline --author=<me> | grep -v '^+++ ' | grep '^+' | sed 's/^+//'

Upvotes: 1

Jan Blumschein
Jan Blumschein

Reputation: 172

Maybe filter the output of git show -p:

git log --author="..." --format=format:%H \
  | xargs git show -p --dst-prefix=never-used-string/ \
  | sed -n '/never-used-string/! s/^+\(.*\)/\1/p'

should give you almost what you need (provided that never-used-string does not appear anywhere in your code). Not sure about merge commits and the like...

Upvotes: 0

Related Questions