[英]How to count number of commits per file pathname by author in a Git repository?
剛剛意識到,如果你使用--name-only
打印文件名,漂亮的格式為空字符串,並使用此方法進行排序,uniq,並按最大提交次數排序,在* nix / OS X中,您可以使用:
git log --name-only --author=John --pretty=format: | sort | uniq -c | sort -nr
確保您使用的是正確的作者。
例如,如果我們試圖在Rails中找到DHH的作者,我們可能會這樣做:
git log --format='%aN <%aE>' | LC_ALL='C' sort -u | grep avid
並注意到DHH在Rails git repo中的所有作者都使用“David Heinemeier Hansson”這個名字。 那么,我們可以這樣做:
git log --name-only --author="David Heinemeier Hansson" --pretty=format: | sort | uniq -c | sort -nr
可能輸出:
3624
611 actionpack/CHANGELOG
432 activerecord/CHANGELOG
329 railties/CHANGELOG
206 activerecord/lib/active_record/base.rb
195 activesupport/CHANGELOG
157 actionpack/lib/action_controller/base.rb
153 railties/Rakefile
108 activerecord/lib/active_record/associations.rb
79 actionpack/lib/action_view/helpers/javascript_helper.rb
75 activerecord/lib/active_record/validations.rb
74 activerecord/test/base_test.rb
69 actionmailer/CHANGELOG
66 railties/lib/rails_generator/generators/applications/app/app_generator.rb
66 activerecord/Rakefile
66 actionpack/lib/action_controller/caching.rb
60 actionpack/lib/action_controller/routing.rb
59 railties/lib/initializer.rb
59 actionpack/Rakefile
57 actionpack/lib/action_controller/request.rb
...
因此,截至2015-02-21,Rails git repo中有3624個文件,看起來他從未親自提交過,文件提交的最大數量是611提交的ActionPack CHANGELOG,其次是ActiveRecord CHANGELOG和ActiveRecord :: Base是他提交的最多的Ruby文件。
如果要排除計數中未觸及的文件數,請使用--format=
而不是--pretty=format:
,例如:
git log --name-only --author="David Heinemeier Hansson" --format: | sort | uniq -c | sort -nr
顯示當前工作樹中每個文件的指定作者的提交計數。
$author = 'shaun';
dir -r | % { New-Object PSObject -Property `
@{ `
Count = git rev-list HEAD --count --author=$author -- $_.Name; `
FileName = $_.Name; `
}} `
| sort Count | % { $_.Count + ' -- ' + $_.FileName + ' -- ' + $author; }
$author = 'shaun'; `
Get-ChildItem -recurse | ForEach-Object `
{ `
New-Object PSObject -Property `
@{ `
Count = git rev-list HEAD --count --author=$author -- $_.Name; `
FileName = $_.Name; `
} `
} | `
Sort-Object Count | ForEach-Object `
{ `
$_.Count + ' -- ' + $_.FileName + ' -- ' + $author; `
}
`
表示在新行上繼續執行命令。 |
表示將結果對象傳遞給下一個命令。 $_.SomeProperty
從對象管道訪問屬性。 `
標記表示新行。 filter-branch
也跟蹤先前刪除文件和其他分支。 git log --format='%aN' | sort -u
git log --format='%aN' | sort -u
迭代所有項目作者 0 -- blame.txt~ -- shaun
0 -- .blame.txt.un~ -- shaun
1 -- GitBook-GitTools-06-RewritingHistory.asc -- shaun
1 -- GitBook-GitTools-05-Searching.asc -- shaun
1 -- GitBook-GitTools-03-StashingAndCleaning.asc -- shaun
1 -- GitBook-GitTools-07-ResetDemystified.asc -- shaun
1 -- README.md -- shaun
1 -- LICENSE -- shaun
1 -- GitBook-GitTools-09-Rerere.asc -- shaun
1 -- GitBook-GitBranching-Rebasing.asc -- shaun
1 -- blame2.txt -- shaun
1 -- GitBook-GettingStarted-FirstTimeSetup.asc -- shaun
1 -- GitBook-GitTools-02-InteractiveStaging.asc -- shaun
1 -- GitBook-GitTools-01-RevisionSelection.asc -- shaun
1 -- GitBook-GitInternals-Maintenance.asc -- shaun
2 -- goals.asc -- shaun
2 -- GitBook-GitTools-10-Debugging.asc -- shaun
3 -- blame.txt -- shaun
6 -- GitBook-GitTools-08-AdvancedMerging.asc -- shaun
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.