如何修改Git,删除和删除新行号

时间:2013-02-26 06:04:07

标签: git

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

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

任何人都可以帮我解决这个问题。

1 个答案:

答案 0 :(得分: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(-)