git:在 release/tag 中获取 *新* 贡献者(作者)列表
git: get *new* contributors (authors) list in release/tag
我正在为发布准备变更日志并进行一些统计。
列出以前版本的贡献者非常容易:
git shortlog -s -e -n TAG..
审稿人:
git log TAG.. | grep -Ei '(reviewed|acked)-by:' |sed 's/.*by: //' | sort | uniq -c | sort -n -r
提交者:
git shortlog -s -e -n -c TAG..
但是如何列出自 TAG
以来的新贡献者(作者)(例如那些在 TAG
之前没有提交过的人)?
假设可以使用bash
,至少有两种方式:
#!/bin/bash
set -e
OLD_COMMIT=""
NEW_COMMIT=""
if test -z "$OLD_COMMIT" || test -z "$NEW_COMMIT"; then
echo 'fatal: must provide OLD_COMMIT and NEW_COMMIT commits' >&2
exit 1
fi
shift 2
首先,使用在 bash 4 中引入的声明性数组(以命令方式模拟右外连接):
declare -A OLD_AUTHORS
while read -r OLD_AUTHOR; do
OLD_AUTHORS["$OLD_AUTHOR"]=1
done < <(git log --pretty=format:%aN "$OLD_COMMIT")
declare -A NEW_AUTHORS
while read -r NEW_AUTHOR; do
if test -z ${OLD_AUTHORS["$NEW_AUTHOR"]}; then
NEW_AUTHORS["$NEW_AUTHOR"]=1
fi
done < <(git log --pretty=format:%aN "$OLD_COMMIT"~1.."$NEW_COMMIT")
for NEW_AUTHOR in "${!NEW_AUTHORS[@]}"; do
echo "$NEW_AUTHOR"
done | sort
或者,第二种,使用管道和更具声明性的方式:
diff \
<(git log --pretty=format:%aN "$OLD_COMMIT" | sort | uniq) \
<(git log --pretty=format:%aN "$OLD_COMMIT"~1.."$NEW_COMMIT" | sort | uniq) \
| grep '^> ' \
| cut -c 3-
以上两种解决方案都可以处理以下历史(git log --pretty=format:'%h %d% aN'
):
c3d766e (tag: v2) Keith
cffddc6 New John
ee3cc52 Dan
c307f13 (tag: v1) New John
ae3c4a3 New John
9ed948e Old John
7eb548a Old John
像这样 (show-new-authors.sh v1 v2
):
Dan
Keith
我正在为发布准备变更日志并进行一些统计。
列出以前版本的贡献者非常容易:
git shortlog -s -e -n TAG..
审稿人:
git log TAG.. | grep -Ei '(reviewed|acked)-by:' |sed 's/.*by: //' | sort | uniq -c | sort -n -r
提交者:
git shortlog -s -e -n -c TAG..
但是如何列出自 TAG
以来的新贡献者(作者)(例如那些在 TAG
之前没有提交过的人)?
假设可以使用bash
,至少有两种方式:
#!/bin/bash
set -e
OLD_COMMIT=""
NEW_COMMIT=""
if test -z "$OLD_COMMIT" || test -z "$NEW_COMMIT"; then
echo 'fatal: must provide OLD_COMMIT and NEW_COMMIT commits' >&2
exit 1
fi
shift 2
首先,使用在 bash 4 中引入的声明性数组(以命令方式模拟右外连接):
declare -A OLD_AUTHORS
while read -r OLD_AUTHOR; do
OLD_AUTHORS["$OLD_AUTHOR"]=1
done < <(git log --pretty=format:%aN "$OLD_COMMIT")
declare -A NEW_AUTHORS
while read -r NEW_AUTHOR; do
if test -z ${OLD_AUTHORS["$NEW_AUTHOR"]}; then
NEW_AUTHORS["$NEW_AUTHOR"]=1
fi
done < <(git log --pretty=format:%aN "$OLD_COMMIT"~1.."$NEW_COMMIT")
for NEW_AUTHOR in "${!NEW_AUTHORS[@]}"; do
echo "$NEW_AUTHOR"
done | sort
或者,第二种,使用管道和更具声明性的方式:
diff \
<(git log --pretty=format:%aN "$OLD_COMMIT" | sort | uniq) \
<(git log --pretty=format:%aN "$OLD_COMMIT"~1.."$NEW_COMMIT" | sort | uniq) \
| grep '^> ' \
| cut -c 3-
以上两种解决方案都可以处理以下历史(git log --pretty=format:'%h %d% aN'
):
c3d766e (tag: v2) Keith
cffddc6 New John
ee3cc52 Dan
c307f13 (tag: v1) New John
ae3c4a3 New John
9ed948e Old John
7eb548a Old John
像这样 (show-new-authors.sh v1 v2
):
Dan
Keith