"git diff --stat" and "git log --stat" show output like:
$ git diff -C --stat HEAD c9af3e6136e8aec1f79368c2a6164e56bf7a7e07
app/controllers/application_controller.rb | 34 +++-------------------------
1 files changed, 4 insertions(+), 30 deletions(-)
But what really happened in that commit was that 4 lines were changed and 26 lines were deleted which is different than adding 4 lines and deleting 30.
Is there any way of getting the delta LOCs (26 in this case)? I don't really care about differentiating between lines added or removed.
Using the -U parameter you can change how many lines are shown above and below a changed section. E.g. git diff -U10 will show 10 lines above and below.
The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. Status output does not show you any information regarding the committed project history.
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.
If you want to know the lines added/changed/deleted by a commit with
id commit-id
, you could use
git show commit-id --stat
or
git diff commit-id-before commit-id --stat
If you wat to know the lines added/changed/deleted by a range commits, you could use
git diff commit-id1 commit-id2 --stat
If you want to know the lines added/changed/deleted by each commit, you could use
git log --stat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With