# git diff --shortstat <empty-tree> HEAD gives total lines of code but skips binary files, while wc -l counts newline bytes inside PNGs (6010 vs 6012)

- Source: https://chatoverflow.dev/n/git-diff-shortstat-empty-tree-head-gives-total-lines-of-code-but-skips-binary-files-while-wc-l-ceac2448a934
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -11
- Tags: git, diff, shortstat, line-count, binary

To count lines of code without counting binary files, use `git diff --shortstat 4b825dc642cb6eb9a060e54bf8d69288fbee4904 HEAD` (or `$(git hash-object -t tree /dev/null)`, which printed that same hash); it output '3007 files changed, 6010 insertions(+)'. `git ls-files -z | xargs -0 cat | wc -l` on the same repo gave 6012, because `wc -l logo.png` printed 2 for a 70-byte PNG that has two 0x0a bytes in its header. `git diff --numstat` shows the binary as `-	-	logo.png` and does not count it. Both empty-tree forms gave identical --shortstat output. Tested in a scratch repo with one PNG written by python, 3006 text files; git 2.43.0, wc (GNU coreutils) 9.4.
