Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6602701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:54:28+00:00 2026-05-25T18:54:28+00:00

General question How can I tell git , that it should also count empty

  • 0

General question

How can I tell git, that it should also count empty lines in a diff, when using git log --stat?

Code example

git clone https://github.com/voldemort/voldemort.git
cd voldemort
git log --numstat -n 1 c21ad76 contrib/hadoop-store-builder/src/java/voldemort/store/readonly/mr/HadoopStoreBuilderReducer.java
git show c21ad76 -- contrib/hadoop-store-builder/src/java/voldemort/store/readonly/mr/HadoopStoreBuilderReducer.java

More details

In the given example git log --numstat claims for commit c21ad76, that file HadoopStoreBuilderReducer.java has 25 added and 22 removed lines . If you have a closer look at the diff output (git show) of that file you can see, that there are actually 30 added and 25 removed lines, which make it different by 5 added and 3 deleted lines. At an even closer look, there are 5 empty lines inside the added lines hunk and 4 empty lines in the deleted lines hunk.

This behavior is the same with git log --shortstat or git log --stat.

It appears to me, that all empty lines, which are inside an hunk are not counted by git log --numstat.

How can I calculate with git the number of added and removed lines per commit including blank lines?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:54:28+00:00Added an answer on May 25, 2026 at 6:54 pm

    Context

    There are several different (valid) patches for the same change. The main difference is the use of context lines. Unified diff usually uses three lines of context before and after each change. Internally git (sometimes) uses zero lines of context which can result to different changed lines.

    First solution: external tool

    As @karl-bielefeldt already described, one can pipe the result of git show into grep -Pc '^\+(?!\+)' or grep -Pc '^-(?!-)'. There is the tool diffstat which does exactly that:

    $git show c21ad76 -- contrib/hadoop-store-builder/src/java/voldemort/store/readonly/mr/HadoopStoreBuilderReducer.java | diffstat
     HadoopStoreBuilderReducer.java |   57 +++++++++++++++++++++--------------------
     1 file changed, 30 insertions(+), 27 deletions(-)
    

    Second solution: use different contexts for the patch

    The output patch of git show can be configured. With the option “-Ux” for x a context can be specified.

    $git show -U0 c21ad76 -- contrib/hadoop-store-builder/src/java/voldemort/store/readonly/mr/HadoopStoreBuilderReducer.java | diffstat
     HadoopStoreBuilderReducer.java |   47 +++++++++++++++++++++--------------------
     1 file changed, 25 insertions(+), 22 deletions(-)
    

    This matches the internal git log --numstat because it uses a 0 context for calculating the stat. Note that this behaviour is about to change in git version 1.7.7. With that numstat uses 3 lines of context.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

general question is i like to build logger class that writes to single log
This is a general question I haven't seen an answer for. Can I tell
This is a general question. And may not be specific to datagrids. How can
I have a general question that is rather open-ended (i.e. depends on platform, application
I understand this question can be general but, specifically with regards to ASP.NET MVC,
I have one general question about optimization at SQL Server: How I can reduce
Yes, I know that general forms of this question have been asked time and
This is just a general question - I was sitting and waiting for a
Just a general question about what the best practice is: public void Foo() {
Ok this is a general question about how to solve this issue, not to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.