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.

  • visualizing changes branch in visual studio 2013
  • Using git to track only some of a Unity project
  • How to merge many commits into one in github repository
  • Git recommended workflow
  • push my changes made in gerrit to github repository
  • git-flow: workflow for making “release candidates” / QA web artifacts
  • 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.

  • In git, what is the difference between merge --squash and rebase?
  • Single working branch with Git
  • Mercurial <--> git cheat sheet?
  • how to pull out a commit from git history?
  • Does git-flow merging scale well for larger teams?
  • Setting Up Environments with SaltStack
  • 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.