0

I've found it's feasible to count total lines changed by a specific author in a "git repository".
I've also found it's feasible to count total lines changed between 2 commits.
git diff --shortstat commit1...commit2.

But I didn't found how to count total lines changed by a specific author between 2 commits.
Actually in my case, there is a branch with several commits from different authors, it's easy to found total lines changed for the Merge request between the branch to master, but I don't know how to find the contribution from an author of the MR.

What I want is like the result of git diff --shortstat, but show only contribution from the specific user.
author:xxx: aa files changed, bb insertions(+), cc deletions(-)

  • I actually copy-pasted your question and [found something very similar](https://stackoverflow.com/a/1265229/11261546) – Ivan Jun 30 '21 at 14:22
  • I've checked that answer, i think it does not fit my question, a similar one could be. "git log xx...xx --shortstat --author="xx" | grep -E "fil(e|es) changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed: ", files, "lines inserted: ", inserted, "lines deleted: ", deleted }' " but unfortunately it calculates all commits separately which is inaccurate. – user2699165 Jun 30 '21 at 14:41
  • @user2699165 why would calculating the commits separately be inaccurate? – mnestorov Jun 30 '21 at 15:07
  • @user2699165 Although this is quite similar to what you posted, could you try it with [this](https://gist.github.com/Anarcroth/fe80ddbac1e312ac2501415fdb956ef7) command. It's too long to post it as a comment. – mnestorov Jun 30 '21 at 15:21
  • @mnestorov yes, this one has the same result comparing to my paste, what I expect is accurate contribution line from a user in a singe MR/PR, multiple commits could target to same file same line many times, thus make it inaccurate. – user2699165 Jul 01 '21 at 02:18

1 Answers1

1

Assuming all of the commits in the range are not made by one author, then the recommendation in this answer is correct and is the best answer possible.

It is not, in general, possible to avoid calculating commits separately if all the commits you want to consider are not consecutive. When they are consecutive, you can perform a diff between the beginning and ending commits, and then see the total results. However, when you want to pick only some commits, such as only those by a specific author, you can't do that and you need to rely on individual diffs.

You could, of course, try to cherry-pick all of the commits from that one author onto a separate branch and then diff from the beginning to the end, but oftentimes multiple users will have interacted with that code, and the cherry-picks will have conflicts. In that situation, it's hard to speak usefully about the contributions of a single author to that code at all in the absence of other contributors. You can still try it if you want, and it may work in some situations, but it won't work in all cases.

And, of course, I should point out that lines of code aren't generally a good indication of the quality or performance of a developer, and since these measurements shouldn't be used for comparing developers, their precision is a little less important.

bk2204
  • 64,793
  • 6
  • 84
  • 100