[git] Git 리포지토리에서 특정 작성자가 변경 한 총 줄 수를 계산하는 방법은 무엇입니까?

Git 저장소에서 특정 작성자가 변경 한 행을 계산하는 호출 할 수있는 명령이 있습니까? Github이 Impact 그래프에 대해이 작업을 수행함에 따라 커밋 수를 계산하는 방법이 있어야한다는 것을 알고 있습니다.



답변

다음 명령의 출력은 총계를 더하기 위해 스크립트로 전송하기가 합리적으로 쉽습니다.

git log --author="<authorname>" --oneline --shortstat

현재 HEAD에 대한 모든 커밋에 대한 통계를 제공합니다. 다른 지점에 통계를 추가하려면에 통계를 제공해야합니다 git log.

스크립트에 전달하기 위해 빈 로그 형식으로 “oneline”형식을 제거 할 수도 있으며 Jakub Narębski의 의견에 따르면 --numstat다른 대안입니다. 행당 통계보다는 파일 단위로 생성되지만 구문 분석이 더 쉽습니다.

git log --author="<authorname>" --pretty=tformat: --numstat


답변

이것은 저자에 대한 통계를 제공하고 필요에 따라 수정합니다.

Gawk 사용하기 :

git log --author="_Your_Name_Here_" --pretty=tformat: --numstat \
| gawk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s\n", add, subs, loc }' -

Mac OSX에서 Awk 사용 :

git log --author="_Your_Name_Here_" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -

편집 (2017)

github에는 매끄러운 것처럼 보이고 bash를 종속성으로 사용하는 새로운 패키지가 있습니다 (Linux에서 테스트 됨). 스크립트보다는 직접 사용에 더 적합합니다.

그것은의 자식-빠른 통계 (GitHub의 링크) .

git-quick-stats폴더에 복사 하고 경로에 폴더를 추가하십시오.

mkdir ~/source
cd ~/source
git clone git@github.com:arzzen/git-quick-stats.git
mkdir ~/bin
ln -s ~/source/git-quick-stats/git-quick-stats ~/bin/git-quick-stats
chmod +x ~/bin/git-quick-stats
export PATH=${PATH}:~/bin

용법:

git-quick-stats

여기에 이미지 설명을 입력하십시오


답변

누구나 자신의 코드베이스에서 모든 사용자 의 통계를보고 싶을 최근 두 명의 동료 가이 끔찍한 원 라이너를 생각해 냈습니다.

git log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}'

(약 10-15k 커밋이있는 리포지토리를 통해 몇 분이 소요됩니다.)


답변

힘내 명성 https://github.com/oleander/git-fame-rb

커밋 및 수정 된 파일 수를 포함하여 모든 작성자의 수를 한 번에 계산할 수있는 유용한 도구입니다.

sudo apt-get install ruby-dev
sudo gem install git_fame
cd /path/to/gitdir && git fame

https://github.com/casperdcl/git-fame(@fracz 에서 언급 )에도 Python 버전이 있습니다 .

sudo apt-get install python-pip python-dev build-essential
pip install --user git-fame
cd /path/to/gitdir && git fame

샘플 출력 :

Total number of files: 2,053
Total number of lines: 63,132
Total number of commits: 4,330

+------------------------+--------+---------+-------+--------------------+
| name                   | loc    | commits | files | percent            |
+------------------------+--------+---------+-------+--------------------+
| Johan Sørensen         | 22,272 | 1,814   | 414   | 35.3 / 41.9 / 20.2 |
| Marius Mathiesen       | 10,387 | 502     | 229   | 16.5 / 11.6 / 11.2 |
| Jesper Josefsson       | 9,689  | 519     | 191   | 15.3 / 12.0 / 9.3  |
| Ole Martin Kristiansen | 6,632  | 24      | 60    | 10.5 / 0.6 / 2.9   |
| Linus Oleander         | 5,769  | 705     | 277   | 9.1 / 16.3 / 13.5  |
| Fabio Akita            | 2,122  | 24      | 60    | 3.4 / 0.6 / 2.9    |
| August Lilleaas        | 1,572  | 123     | 63    | 2.5 / 2.8 / 3.1    |
| David A. Cuadrado      | 731    | 111     | 35    | 1.2 / 2.6 / 1.7    |
| Jonas Ängeslevä        | 705    | 148     | 51    | 1.1 / 3.4 / 2.5    |
| Diego Algorta          | 650    | 6       | 5     | 1.0 / 0.1 / 0.2    |
| Arash Rouhani          | 629    | 95      | 31    | 1.0 / 2.2 / 1.5    |
| Sofia Larsson          | 595    | 70      | 77    | 0.9 / 1.6 / 3.8    |
| Tor Arne Vestbø        | 527    | 51      | 97    | 0.8 / 1.2 / 4.7    |
| spontus                | 339    | 18      | 42    | 0.5 / 0.4 / 2.0    |
| Pontus                 | 225    | 49      | 34    | 0.4 / 1.1 / 1.7    |
+------------------------+--------+---------+-------+--------------------+

그러나 Jared의 의견에서 언급했듯이 매우 큰 저장소에서 처리하는 데 몇 시간이 걸립니다. 그것이 너무 많은 Git 데이터를 처리해야한다는 것을 고려할 때 그것이 향상 될 수 있는지 확실하지 않습니다.


답변

다음은 현재 코드베이스에 가장 많은 행을 가진 사람을 보는 데 유용한 것으로 나타났습니다.

git ls-files -z | xargs -0n1 git blame -w | ruby -n -e '$_ =~ /^.*\((.*?)\s[\d]{4}/; puts $1.strip' | sort -f | uniq -c | sort -n

다른 답변은 커밋에서 변경된 행에 주로 초점을 맞추었지만 커밋이 살아남지 않고 덮어 쓰면 이탈했을 수 있습니다. 위의 주문은 또한 모든 커미터를 한 번에 하나씩이 아니라 한 줄씩 정렬하도록합니다. git blame (-C -M)에 몇 가지 옵션을 추가하여 파일 간 파일 이동 및 줄 이동을 고려한 더 나은 숫자를 얻을 수 있지만 명령을 실행하면 명령이 훨씬 오래 실행될 수 있습니다.

또한 모든 커미터에 대한 모든 커밋에서 변경된 행을 찾으려면 다음 작은 스크립트가 도움이됩니다.

http://git-wt-commit.rubyforge.org/#git-rank-contributors


답변

주어진 브랜치에서 주어진 저자 (또는 모든 저자) 의 커밋 수를 세려면 git-shortlog를 사용할 수 있습니다 . git 저장소에서 실행될 때 특히 해당 옵션 --numbered--summary옵션을 참조하십시오 .

$ git shortlog v1.6.4 --numbered --summary
  6904  Junio C Hamano
  1320  Shawn O. Pearce
  1065  Linus Torvalds
    692  Johannes Schindelin
    443  Eric Wong


답변

보고 후 알렉스Gerty3000 의 대답, 나는 한 줄을 단축하는 것을 시도했다 :

기본적으로 git log numstat를 사용하고 변경된 파일 수를 추적 하지 않습니다 .

Mac OSX에서 Git 버전 2.1.0 :

git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done

예:

Jared Burrows   added lines: 6826, removed lines: 2825, total lines: 4001