Git: Show every line added by user in current branch
-
12-12-2019 - |
Question
I would like a certain 'non-technical' person to have a better idea of what I am actually doing when I work on a certain github project. I would like to create a text file with ALL the code I have added to the main branch of this project. I want to put it in a text editor and scroll down all of it, for however many screens. That's basically what I want, for this reason, a 'number of lines' or 'number of characters' stat would not have the same impact.
Specifically, what I want to show is: (first choice) all the lines ever added by me, even if they were removed later.
(second choice) all the lines I contributed in the latest version (we only have one branch)
Is there a way to do this, or at least just print out all the lines in the current branch? (I wrote over 90% of them anyway)
I know that by itself this is not terribly useful, but I feel this is one script away from something more useful such as i.e. number of lines.
Background -> I am relatively new to Git, I am using it from the command line on Windows. I have some linux experience so this doesn't bother me too much. I am also using Github for this project and I have access to the github for windows client (though I don't really use it).
Solution
Try this:
git show $(git rev-list --author="Your Name" HEAD)
This shows diffs, not "added lines", but diffs are more meaningful. No automated procedure can decide whether a line that was replaced with a different line should be considered an addition or just a modification.
OTHER TIPS
You could try something like the following to get a "minimal" (with zero lines of context instead of three) patch of all your changes:
for h in $(git --no-pager log --author='name' --format='%H' HEAD); do git --no-pager diff-tree -U0 $h; done >mychanges.txt
mychanges.txt
should give the "non-technical" person some idea of what you've done; all they really need to understand is that lines starting with +
are lines you added and lines starting with -
are lines you deleted. Walk through a few diffs for some files and they'll get the hang of it and should be able to read the rest of the file on their own.