Using git diff, how can I get added and modified lines numbers?

前端 未结 12 2030
清酒与你
清酒与你 2020-11-30 22:13

Assuming I have a text file

alex
bob
matrix
will be removed
git repo

and I have updated it to be

alex
new line here
another         


        
12条回答
  •  时光取名叫无心
    2020-11-30 22:54

    Here's a bash function I cobbled together:

    echo ${f}:
    for n in $(git --no-pager blame --line-porcelain $1 |
            awk '/author Not Committed Yet/{if (a && a !~ /author Not Committed Yet/) print a} {a=$0}' |
            awk '{print $3}') ; do
        if (( prev_line > -1 )) ; then
            if (( "$n" > (prev_line + 1) )) ; then
                if (( (prev_line - range_start) > 1 )) ; then
                    echo -n "$range_start-$prev_line,"
                else
                    echo -n "$range_start,$prev_line,"
                fi
                range_start=$n
            fi
        else
            range_start=$n
        fi
        prev_line=$n
    done
    if (( "$range_start" != "$prev_line" )) ; then
        echo "$range_start-$prev_line"
    else
        echo "$range_start"
    fi
    

    And it ends up looking like this:

    views.py:
    403,404,533-538,546-548,550-552,554-559,565-567,580-582
    

提交回复
热议问题