How to show number of lines added and deleted for every file in git log and git diff?

2.5k Views Asked by At

If I do git log <commit-id> --stat or git diff with --stat, I get something like:

myproj/src/__main__.py                             |   1 +
myproj/{ => src}/utils.py                          |   0
myproj/{ => src}/web.py                            |  31 ++++-
3 files changed, 29 insertions(+), 3 deletions(-)

The number next to each file is: number_of_inserts + number_of_deletes. This is not what I want. I want to know the number of lines added and deleted for each file (e.g. +28 -3 instead of 31).

  • I know I could use --numstat instead of --stat, but --numstat will not produce the histogram.
  • I also know that I can use diffstat. For example, git diff <commit-id> | diffstat -f4 -C:

    myproj/src/__main__.py                             |   1    1    0 +
    myproj/src/web.py                                  |  31   28    3 ++++-
    2 files changed, 29 insertions(+), 3 deletions(-)
    

    But here I lose information about file moves/renames (e.g. myproj/{ => src}/web.py).

So how can I get output similar to --stat, but with information about the number of lines added and the number of lines deleted for each file?

1

There are 1 best solutions below

0
idlethread On

git log --numstat --stat --oneline outputs the following:

6012d9a9fa69 docs: kvm: Convert timekeeping.txt to ReST format
1       0       Documentation/virt/kvm/index.rst
128     95      Documentation/virt/kvm/{timekeeping.txt => timekeeping.rst}
 Documentation/virt/kvm/index.rst                            |   1 +
 Documentation/virt/kvm/{timekeeping.txt => timekeeping.rst} | 223 +++++++++++++++++++++++++++++++++++++++++++++----------------------------------
 2 files changed, 129 insertions(+), 95 deletions(-)