Is there a way of having git show lines added, lines changed and lines removed?

You can use:

git diff --numstat

to get numerical diff information.

As far as separating modification from an add and remove pair, --word-diff might help. You could try something like this:

MOD_PATTERN='^.+(\[-|\{\+).*$' \
ADD_PATTERN='^\{\+.*\+\}$' \
REM_PATTERN='^\[-.*-\]$' \
git diff --word-diff --unified=0 | sed -nr \
    -e "s/$MOD_PATTERN/modified/p" \
    -e "s/$ADD_PATTERN/added/p" \
    -e "s/$REM_PATTERN/removed/p" \
    | sort | uniq -c

It’s a little long-winded so you may want to parse it in your own script instead.

Leave a Comment