我想查看刪除/添加行的數量,按照作者爲git歷史中給定分支分組的數量。有git shortlog -s
,它顯示了每個作者的提交數量。有沒有類似的東西可以得到一個完整的diffstat?顯示每個作者在git中更改的行數
回答
由於the SO question "How to count total lines changed by a specific author in a Git repository?"並不完全令人滿意,commandlinefu有替代品(而不是每個分支雖然):
git ls-files | while read i; do git blame $i | sed -e 's/^[^(]*(//' -e 's/^\([^[:digit:]]*\)[[:space:]]\+[[:digit:]].*/\1/'; done | sort | uniq -ic | sort -nr
它包括二進制文件,這是不好的,所以你可以(除去真正隨機二進制文件):
git ls-files | grep -v "\.\(pdf\|psd\|tif\)$"
(注:如由commentedtrcarden,一個-x
或--exclude
選項是行不通的
從git ls-files
man page,git ls-files -x "*pdf" ...
只會排除未經跟蹤內容,如果--others
或--ignored
添加到git ls-files
命令)
或者:
git ls-files "*.py" "*.html" "*.css"
只包括特定的文件類型。
儘管如此,"git log
"-based solution應該會更好,如:
git log --numstat --pretty="%H" --author="Your Name" commit1..commit2 | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'
但同樣,這也是一個路徑(這裏是2提交),而不是每枝所有分支。
這裏的腳本將做到這一點。把它放入authorship.sh,chmod + x它,你就全都設置好了。
#!/bin/sh
declare -A map
while read line; do
if grep "^[a-zA-Z]" <<< "$line" > /dev/null; then
current="$line"
if [ -z "${map[$current]}" ]; then
map[$current]=0
fi
elif grep "^[0-9]" <<<"$line" >/dev/null; then
for i in $(cut -f 1,2 <<< "$line"); do
map[$current]=$((map[$current] + $i))
done
fi
done <<< "$(git log --numstat --pretty="%aN")"
for i in "${!map[@]}"; do
echo -e "$i:${map[$i]}"
done | sort -nr -t ":" -k 2 | column -t -s ":"
在Mac OS X 10.6.8和Debian Linux 5.0.8上使用這個:'/ Users/slippyd/Desktop/git-authorship:line 3:declare:-A:invalid option declare:usage:declare [-afFirtx] [-p] [name [= value] ...]' – 2012-01-27 17:10:06
這個腳本非常好用。謝謝! – ColinM 2012-03-07 17:43:31
在mac上得到與slipp相同的錯誤,我將-A更改爲-a(如錯誤消息中指定的那樣),但腳本無論如何都失敗了,顯然它沒有處理名稱中的空格(如第一個和第姓氏),仍然看起來有效的解決方案,你可能會認爲這是許多人需要的東西,以獲得晉升:),顯然不是。好吧,我只會說90%的老闆! – 2013-09-28 00:03:12
從How to count total lines changed by a specific author in a Git repository?
以下命令的輸出應該是相當容易發送到腳本加起來的總數:
git log --author="<authorname>" --oneline --shortstat
這給所有提交統計數據對當前HEAD 。如果你想在其他分支添加統計信息,你將不得不將它們作爲參數提供給git log。
這是一個老的文章,但如果有人仍然在尋找它:
安裝git的額外
brew install git-extras
然後
git summary --line
在我的回購協議我已經在這裏漂浮的單線隊員獲得了很多垃圾輸出是一個Python腳本做是正確的:
import subprocess
import collections
import sys
def get_lines_from_call(command):
return subprocess.check_output(command).splitlines()
def get_files(paths=()):
command = ['git', 'ls-files']
command.extend(paths)
return get_lines_from_call(command)
def get_blame(path):
return get_lines_from_call(['git', 'blame', path])
def extract_name(line):
"""
Extract the author from a line of a standard git blame
"""
return line.split('(', 1)[1].split(')', 1)[0].rsplit(None, 4)[0]
def get_file_authors(path):
return [extract_name(line) for line in get_blame(path)]
def blame_stats(paths=()):
counter = collections.Counter()
for filename in get_files(paths):
counter.update(get_file_authors(filename))
return counter
def main():
counter = blame_stats(sys.argv[1:])
max_width = len(str(counter.most_common(1)[0][1]))
for name, count in reversed(counter.most_common()):
print('%s %s' % (str(count).rjust(max_width), name))
if __name__ == '__main__':
main()
注意,參數的腳本將被傳遞到git ls-files
,所以如果你只是想顯示Python文件: blame_stats.py '**/*.py'
如果你只是想在一個子目錄中顯示文件:blame_stats.py some_dir
依此類推。
- 1. Git rebase更改作者?
- 2. 每個作者在django中的每個作者的書數
- 3. 混帳推後更改的git作者
- 4. Git:顯示無法更改的更改不顯示?
- 5. 顯示網格中的總行數每次更改名稱
- 6. 在git存儲庫中爲每個作者計算代碼行數
- 7. 每個配置更改顯示名稱
- 8. 在作者字段中顯示密碼的Git日誌
- 9. 在MonoTouch中更改每個配置的顯示名稱
- 10. 更改Netbeans中的Git提交者
- 11. 顯示每個用戶的git影響
- 12. `git stash --patch`顯示的行改變了`git diff` /`git status`沒有顯示
- 13. phpMyAdmin:更改顯示的默認行數?
- 14. 在Git中獲取一個文件行更改的總數
- 15. 如何查看查找git log中每個文件更改的行數
- 16. Tortoise GIT - 合併後顯示在分支中創建的更改
- 17. 如何顯示在git日誌中更改的完整文件
- 18. 每頁顯示的行數?
- 19. WordPress循環顯示每個作者的1篇文章
- 20. 在git中顯示每個分支的最近提交
- 21. 如何用`git log`搜索更改並顯示匹配的行?
- 22. 顯示作者在Wordpress作者檔案中使用的類別
- 23. 每個文件的Git貢獻者
- 24. 獲取每個作者在Git repo的所有分支上的提交數
- 25. Git/Stash - 變更集中沒有作者
- 26. 顯示錶中的每一行數RoR
- 27. Git推送和結賬更改權限後更改不顯示
- 28. Git的作者有時候會改變
- 29. 更改已合併的git commit的作者
- 30. 爲什麼「git log --name-only」顯示一個文件更改,但「git diff」顯示更多?
會http://stackoverflow.com/questions/1265040/how-to-count-total-lines-changed-by-a-specific-author-in-a-git-repository幫助嗎?正如'git短日曆 - 編號--summary' – VonC 2010-05-07 08:42:38
@VonC,我'git shortlog --numbered --summary'與'git shortlog -s -n'相同,它只會顯示提交數量,沒有改變的行 – knittl 2010-05-07 08:53:43