1

Is there a way using git to find out which developers' code was changed by a particular commit?

The process would look something like: Take a commit SHA, get each changed line in the parent commit git diff SHA^!, group them by the author of the line (git blame) and then order them by number of lines and list it out like

Commit SHA### updated code written by the following developers:
Jane Smythe (23 lines)
Rickard Strauss (8 lines)

I am thinking of using this to print to the console when committing (the following devs code were modified, make sure to tag them in your PR), it could even be potentially integrated with Bitbucket/Git to automatically tag devs whose code is being changed or email them etc etc.

I found this gist using python that appears to do something similar, but is going into a separate language other than bash/git necessary for this?

Damon
  • 10,493
  • 16
  • 86
  • 144
  • 1
    I'm just going to put this out there - this is the first good use of blame I've seen, and I feel bad to have not ever thought of it before. –  Dec 18 '17 at 14:30
  • 1
    "is going into a separate language other than bash/git necessary for this?" - I'm not sure if bash alone is powerful enough, but in standard git installation you could also find `perl`, and even if you happen to have minimal windows installation there is `awk`. – max630 Dec 18 '17 at 14:39
  • Realistically I can rely on `node` existing on my whole team always, but a universal solution is preferred if I'm talking about it in public ;) – Damon Dec 18 '17 at 14:43

2 Answers2

1

You could use git-diff-blame https://github.com/dmnd/git-diff-blame

And you could filter by commit sha

MadSquirrel
  • 131
  • 1
  • 10
0

It is not possible to do that reliably, because git would need to distinguish between added and edited lines which doesn't work.

A good approach would be to take the percentage of contributions in the file - before the commit - and address those in the PR which contributed most. This is what github is doing btw.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • 1
    Could we look at the author of each line that was removed in the diff? – Damon Dec 18 '17 at 14:36
  • Where is github doing this? – Damon Dec 18 '17 at 14:36
  • @Damon github is recommending those authors for a review. (Upper right corner at the PR page) – hek2mgl Dec 18 '17 at 15:29
  • @Damon As soon as the change gets non trivial, meaning inserting some lines here, deleting some lines there, the name of the author of a certain line number gets more and more useless. – hek2mgl Dec 18 '17 at 15:31
  • Haven't worked with bitbucket too much. If they don't ship that feature, check this: https://stackoverflow.com/q/4589731/171318 – hek2mgl Dec 18 '17 at 18:32