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

git diff –stat” and “git log –stat” shows things 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.

  • Git can't add file
  • git aws.push Error
  • GitLab-omnibus 7.9 on Banana Pi error when pushing to directory on external hard drive
  • Team member cannot clone repo from BitBucket?
  • How to 'blow away' a GIT merge and start fresh?
  • List all files that are not ignored by .gitignore
  • 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 git to deploy to a cluster
  • Jenkins Git plugin - 401
  • laravel blade files, Your local changes would be overwritten by merge
  • How do you git fetch then merge? “Error: Your local changes to the following files would be overwritten by merge”
  • Why github have a limit on users? Can other users sync from the other user repo?
  • How can I efficiently see the contents of a renamed file maintained under git?
  • 3 Solutions collect form web for “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:

    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.

    1. 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“.
    2. If you wat to know the lines added/changed/deleted by a range
      commits, you could use “git diff commit-id1 commit-id2 –stat
    3. If you want to know the lines added/changed/deleted by each commit,
      you could use “git log –stat

    git uses “unified” diff, which only has added and deleted lines, as the diff format. You have to do something external to get a diff that shows add, delete, and change information. gives links to a script that allows running regular old “diff” – and from that you can generate a “context” diff output. Context diff does show added, removed, and changed lines, which should allow you to get the data you want.

    Git Baby is a git and github fan, let's start git clone.