git diff --unified=0 HEAD~1..HEAD | grep -Po '(^diff --git [a-zA-Z/._]*|^@@.*@@)' | while read l; do if [[ -n ${l##@@*} ]]; then f=${l#*/}; else echo "$f:${l##@@ }" | cut -d' ' -f1 | tr -d '-'; fi; done
解释:
git diff --unified=0 HEAD~1..HEAD
从Git中检索提交信息
grep -Po '(^diff --git [a-zA-Z/._]*|^@@.*@@)'
建立在先前的答案上,并过滤到包含
文件名和行号
为了提高可读性,将一行代码扩展为多行代码:
while read line; do
if [[ -n ${line##@@*} ]]; then
# Grabs filename from this pattern: "diff --git a/....."
filename=${line#*/};
else
# Grabs line number from this patterns: "@@ -<line> +<line> @@"
echo"$filename:${line##@@ }" | cut -d' ' -f1 | tr -d '-';
fi;
done