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.

  • Best practices for using Git with Magento?
  • Git and DiffTool problems : What do LOCAL and REMOTE point to?
  • How to exit a git status list in terminal?
  • How do you use git-cache-meta?
  • Git: Checkout all files except one
  • Manage Keys with Puppet for puppet-vcsrepo
  • 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.

  • Git: commit and automatically add all untracked files
  • Git - fatal: bad default revision 'HEAD' & notice: HEAD points to unborn branch (master)
  • Rollback to uncommited changes after hard reset a Git Repository
  • Bitbucket Webhooks
  • Using git diff in same file between first and last commit
  • Upload my project to github
  • 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.