0

I'd like some help from the git blame/bash/awk gurus. I want to get a list all the people, who appear in the git blame of each file in a particular group of files. Example:

  • files A and B;
  • git blame lists John, Terry, and Merry as authors of various lines in A;
  • git blame lists Jane and Mike as authors of various lines in B;
  • the command takes as input files A and B and returns Jane, John, Terry, Merry, and Mike.

So my idea is this:

  • I finish my work on a branch;
  • execute the command, which take as input all the files, that were modified on this branch compared to master and returns a list of all the authors of lines in these files.

The idea is to know who to ping of a review.

Alexander Popov
  • 23,073
  • 19
  • 91
  • 130
  • [`git shortlog -n -s -- file1 file2…`](https://stackoverflow.com/a/49275435/7976758); see also other answers there. Also search: https://stackoverflow.com/search?q=%5Bgit%5D+list+author+file – phd May 07 '20 at 10:57

2 Answers2

1

You could use log then pipe to sort

git log --all --pretty=format:"%an" -- path/to/fileA path/to/fileB | sort -u

If you want an alias for that, go for

git config --global alias.who '!f() { git log --all --pretty=format:"%aN" -- $1 | sort -u; }; f'

# then just
git who "path/to/fileA path/to/fileB"
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
0

To list the authors of all the lines in a file whose path is $path.

git blame --porcelain -- $path | sed -n -e '/^author /s/^author //p' | uniq -u

To deal with a group of files, like A and B,

for path in A B;do
    git blame --porcelain -- $path
done | sed -n -e '/^author /s/^author //p' | uniq -u
ElpieKay
  • 27,194
  • 6
  • 32
  • 53