1

我正在尝试从上一次提交的 git repo 中获取新添加、修改和删除的行的行号。我正在使用下面的 bash 函数来完成工作。但我无法获得路径值(它显示为空),而且我的行号也不完全符合我的预期。请检查下面的输出。

diff-lines() {
        local path=
        local line=
        while read; do
            esc=$'\033'
            if [[ $REPLY =~ ---\ (a/)?.* ]]; then
                continue
            elif [[ $REPLY =~ \+\+\+\ (b/)?([^[:blank:]$esc]+).* ]]; then
                path=${BASH_REMATCH[2]}
            elif [[ $REPLY =~ @@\ -[0-9]+(,[0-9]+)?\ \+([0-9]+)(,[0-9]+)?\ @@.*]]; then
                line=${BASH_REMATCH[2]}
            elif [[ $REPLY =~ ^($esc\[[0-9;]+m)*([\ +-]) ]]; then
                echo "$path:$line:$REPLY"
                if [[ ${BASH_REMATCH[2]} != - ]]; then
                    ((line++))
                fi
            fi
        done
    }

当我运行脚本时,我得到低于输出

    $ git diff -U0 | diff-lines
    ::+++ b/shipserv/shipserv.cpp
    :1:-
    :1:-// check command-line args
    :1:+// check command-line argsss
    :2:+++ b/shipserv/shipserv_client.cpp
    :3:-// #include <infra/utility/environment/config/PimpConfig.h>
    :3:+// #include <nfra/utility/environment/config/PimpConfig.h>
    :4:+++ b/shipserv/test.text
    :5:-dfssdfsdfsdfsf
    :5:+dfssdfsdfsdfsfZZZZZZZZZZZZZZ
    :6:+modified linsde 9898989
    :7:+New line added

谁能帮我解决这个问题。

4

1 回答 1

1

类似的东西git log -n 1 --stat,也许?在我的回购中:

commit 0e35181e68f628234c53347c00a75d7af37bb45e
Author: Horst H. von Brand <vonbrand@example.com>
Date:   Thu Jan 17 15:46:32 2013 -0300

    The proper bibliography key is oliveiraXXX..., add latest results

    Signed-off-by: Horst H. von Brand <vonbrand@example.com>

 logica.tex | 16 +++++++++++++---
 url.bib    | 45 +++++++++++++++++++++++++++------------------
 2 files changed, 40 insertions(+), 21 deletions(-)
于 2013-02-27T20:24:59.727 回答