git:获取版本/标签中的*新*贡献者(作者)列表

标签 git git-log

我正在准备发布的变更日志并进行一些统计。

列出以前版本的贡献者非常容易:

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="$1"
NEW_COMMIT="$2"
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:获取版本/标签中的*新*贡献者(作者)列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65844331/

相关文章:

pull 时git merge 问题

Git 将原点与带斜杠的分支 merge

git - 防止没有附加参数的 `git stash` 运行

node.js - Heroku:应用程序 fork 后出现 Git 错误

git - 在单独的终端屏幕上显示 git diff 和 git log 输出

python - 在 CircleCi 构建中引用外部私有(private) Git 存储库

git - 如何使用 git log --since 产生可靠的结果

git - 如何在一行中获取带有简短统计信息的 Git 日志?

gitlab - 生成在两个标签之间合并的所有合并请求的列表,所有信息都在 csv 文件中

git - 显示自 master 原始分支点以来 git 分支中的所有提交